Files
2nd/10_Wiki/Topic_Programming/Frontend/Cache miss rates.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

194 lines
5.6 KiB
Markdown

---
id: wiki-2026-0508-cache-miss-rates
title: Cache Miss Rates
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Cache Miss Rate, Cache Hit Rate, Cache Efficiency]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [performance, cache, profiling, cpu, memory]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: agnostic
framework: agnostic
---
# Cache Miss Rates
## 매 한 줄
> **"매 cache lookup 의 fail (data 의 cache 외 fetch) ratio"**. CPU L1/L2/L3 cache, browser HTTP cache, application-level memoization, CDN edge cache 의 universal metric — `miss / (hit + miss)`. 2026 perspective: Apple Silicon M4 의 huge L2 (16MB+), 매 Cloudflare/Fastly tiered cache, 매 LLM prompt-cache (Anthropic) 의 cost-driven optimization.
## 매 핵심
### 매 hierarchy (CPU)
- **L1**: 32-128KB / core, ~1-4 cycles.
- **L2**: 256KB-2MB / core, ~10-15 cycles.
- **L3**: 8-128MB shared, ~40 cycles.
- **DRAM**: >100ns, ~200-300 cycles. 매 miss 의 huge cost.
### 매 miss types (3C)
- **Compulsory** (cold): 매 first access.
- **Capacity**: 매 working set > cache size.
- **Conflict**: 매 set-associative collision.
- (+) **Coherence**: multi-core invalidation.
### 매 measurement
- **CPU**: `perf stat -e cache-misses,cache-references` (Linux).
- **HTTP**: `cf-cache-status: HIT/MISS` headers.
- **App**: hit/miss counter on cache wrapper.
### 매 응용
1. 매 hot loop 의 data layout (SoA vs AoS) tuning.
2. 매 CDN cache key strategy.
3. 매 LLM prompt-cache 의 prefix stability.
## 💻 패턴
### Pattern 1 — 매 cache-friendly layout (SoA)
```ts
// 매 BAD (AoS) — 매 padding / strided access
const particles = [{ x: 0, y: 0, vx: 1, vy: 1 }, /* ... */];
// 매 GOOD (SoA) — 매 sequential, cache-line dense
const xs = new Float32Array(N), ys = new Float32Array(N);
const vxs = new Float32Array(N), vys = new Float32Array(N);
for (let i = 0; i < N; i++) {
xs[i] += vxs[i];
ys[i] += vys[i];
}
```
### Pattern 2 — 매 LRU cache (memoization)
```ts
class LRU<K, V> {
private map = new Map<K, V>();
constructor(private capacity: number) {}
get(key: K): V | undefined {
if (!this.map.has(key)) return;
const v = this.map.get(key)!;
this.map.delete(key);
this.map.set(key, v); // refresh
return v;
}
set(key: K, val: V) {
if (this.map.has(key)) this.map.delete(key);
else if (this.map.size >= this.capacity) {
this.map.delete(this.map.keys().next().value!);
}
this.map.set(key, val);
}
}
```
### Pattern 3 — 매 hit rate metric
```ts
class CountingCache<K, V> {
private hits = 0;
private misses = 0;
constructor(private inner: Map<K, V>, private load: (k: K) => V) {}
get(k: K): V {
if (this.inner.has(k)) { this.hits++; return this.inner.get(k)!; }
this.misses++;
const v = this.load(k);
this.inner.set(k, v);
return v;
}
hitRate(): number { return this.hits / (this.hits + this.misses || 1); }
}
```
### Pattern 4 — 매 HTTP cache header
```http
GET /api/posts/123
Cache-Control: public, max-age=300, stale-while-revalidate=86400
ETag: "abc123"
# CDN response
cf-cache-status: HIT
age: 42
```
### Pattern 5 — 매 stable key (CDN)
```ts
// 매 BAD — query order varies
fetch(`/api/list?b=2&a=1`);
fetch(`/api/list?a=1&b=2`); // 매 different cache key
// 매 GOOD — canonical
const params = new URLSearchParams();
[...Object.entries(args)].sort().forEach(([k, v]) => params.set(k, v));
fetch(`/api/list?${params}`);
```
### Pattern 6 — 매 LLM prompt cache (Anthropic)
```python
# 매 stable system prefix → cache hit (90% cost reduction)
client.messages.create(
model="claude-opus-4-7",
system=[
{"type": "text", "text": LARGE_STABLE_PREFIX,
"cache_control": {"type": "ephemeral"}},
],
messages=[{"role": "user", "content": query}],
)
```
### Pattern 7 — 매 CPU perf measure
```bash
perf stat -e cache-references,cache-misses,L1-dcache-load-misses ./app
# 매 miss rate = misses / references
```
### Pattern 8 — 매 prefetch hint
```ts
// 매 link prefetch (browser)
<link rel="prefetch" href="/next-page" as="document">
// 매 software prefetch (WASM/native via SIMD intrinsics)
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 hot loop slow | profile cache-misses, switch to SoA. |
| 매 CDN low hit rate | normalize key, raise max-age. |
| 매 LLM cost high | prompt-cache stable prefix. |
| 매 working set > cache | partition (tiling), reduce. |
| 매 frequent-but-changing | LRU + TTL. |
**기본값**: 매 measure first (perf, CDN headers, app counter), 매 90%+ hit rate target on hot caches.
## 🔗 Graph
- 부모: [[Performance]]
- 변형: [[CDN]] · [[Memoization]]
- 응용: [[Prompt Cache]]
- Adjacent: [[CPU Overhead]] · [[Buffer Allocation]] · [[Batching]]
## 🤖 LLM 활용
**언제**: 매 cache strategy design, hit rate target setting, prompt-cache prefix structuring.
**언제 X**: 매 hardware-specific cache line size assumption — vendor docs 의.
## ❌ 안티패턴
- **매 cache everything**: 매 cold data cache space waste.
- **매 unstable cache key**: 매 hit rate near zero.
- **매 no eviction**: unbounded memory.
- **매 measuring without baseline**: 매 hit rate alone meaningless — 매 latency / cost outcome 의.
- **매 caching mutable data without invalidation**: stale read bug.
## 🧪 검증 / 중복
- Reference (Hennessy & Patterson, Cloudflare cache docs, Anthropic prompt caching docs).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — cache hierarchy + LRU + HTTP + prompt-cache patterns |