pi-l1-cache 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,11 @@ A high-performance, production-ready **L1 (in-memory) cache** extension for the
|
|
|
11
11
|
|
|
12
12
|
| Feature | Description |
|
|
13
13
|
|---------|-------------|
|
|
14
|
-
| **~
|
|
14
|
+
| **~138µs overhead** | End-to-end per-request cost (measured, incl. key hashing + JSON) |
|
|
15
|
+
| **Fast key hash** | FNV-1a (~1.5µs/op) — no per-request CPU probe on the hot path |
|
|
15
16
|
| **Memory cap** | Hard limit (20MB default) prevents RAM bloat |
|
|
16
17
|
| **Auto-eviction** | LRU-style cleanup when limits reached |
|
|
17
|
-
| **CPU-aware** | Auto-disables when CPU > 95% |
|
|
18
|
+
| **CPU-aware** | Auto-disables when CPU > 95% (checked once at startup) |
|
|
18
19
|
| **TTL-based** | 1-hour default expiry for cached entries |
|
|
19
20
|
| **Atomic cleanup** | Periodic expired entry removal |
|
|
20
21
|
|
|
@@ -22,7 +23,7 @@ A high-performance, production-ready **L1 (in-memory) cache** extension for the
|
|
|
22
23
|
|
|
23
24
|
```
|
|
24
25
|
pi → [L1: RAM Map] → [L2: Redis via LiteLLM] → Provider
|
|
25
|
-
|
|
26
|
+
~138µs ~150ms 1-3s
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
## Installation
|
|
@@ -119,7 +120,7 @@ const DEFAULTS: Settings = {
|
|
|
119
120
|
- **Zero dependencies** — Single TypeScript file
|
|
120
121
|
|
|
121
122
|
### Performance Optimizations
|
|
122
|
-
1. **
|
|
123
|
+
1. **Cheap key hashing** (FNV-1a, ~1.5µs/op). Note: Node's native SHA-256 (OpenSSL) is marginally *faster* than a JS FNV loop — hashing is a rounding error next to `JSON.stringify(messages)`, and both are >1000× below provider latency. The real win is *not* a faster hash, it is skipping the provider call.
|
|
123
124
|
2. **L1 only** — avoid disk I/O in hot path
|
|
124
125
|
3. **Batch eviction** — remove 10-20% at a time, not one-by-one
|
|
125
126
|
4. **Periodic cleanup** — async, non-blocking garbage collection
|
|
@@ -145,6 +146,22 @@ npx tsc --noEmit
|
|
|
145
146
|
- State management & reset
|
|
146
147
|
- Settings override
|
|
147
148
|
|
|
149
|
+
## Benchmark
|
|
150
|
+
|
|
151
|
+
Measured against the published npm artifact (`pi-l1-cache@1.2.1`) on Node 22, using the package's own test hooks and a mocked `ExtensionAPI` with a realistic 15-message conversation history:
|
|
152
|
+
|
|
153
|
+
| Measurement | Result |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `fastHash` (FNV-1a) standalone | ~670k ops/s — 1.49µs/op |
|
|
156
|
+
| Node native `sha256` (for reference) | ~850k ops/s — 1.18µs/op |
|
|
157
|
+
| Full put: hash + map set + size check | ~249k ops/s — 4.0µs/op |
|
|
158
|
+
| Interceptor path (hit *and* miss, 15-msg history) | ~138µs/request |
|
|
159
|
+
| Cache hit vs uncached provider round-trip (1–3s) | ~7,000–20,000× wall-clock |
|
|
160
|
+
| Key uniqueness over 50k synthetic keys | 50,000/50,000 (no collisions) |
|
|
161
|
+
| Eviction under 200-slot cap, 20k inserts | cap held; 19,800 evicted |
|
|
162
|
+
|
|
163
|
+
> ⚠ **Correction:** earlier versions claimed FNV-1a was "~100× faster than SHA256". That was wrong — Node's native SHA-256 is ~0.8× *faster* in practice. The hash was never the bottleneck: `JSON.stringify` dominates the ~138µs per-request cost. Cache hits are keyed by *byte-identical* requests, so real-world hit rate depends on your workload (best for retries, repeated tool calls and same-prompt reruns).
|
|
164
|
+
|
|
148
165
|
## Related Projects
|
|
149
166
|
|
|
150
167
|
- **[opencode-saia-plugin](https://github.com/tobias-weiss-ai-xr/opencode-saia-plugin)** — SAIA provider for OpenCode
|