perf: optimize entries, keys, and values methods#386
Merged
avoidwork merged 3 commits intoavoidwork:masterfrom Jan 14, 2026
Merged
perf: optimize entries, keys, and values methods#386avoidwork merged 3 commits intoavoidwork:masterfrom
avoidwork merged 3 commits intoavoidwork:masterfrom
Conversation
Owner
|
Hi! the benchmarks don't cover the changes you've made. |
Merged
Owner
|
Could you sync with the main branch to get the updated benchmarks, and share the results of |
Owner
|
I did the comparison locally; here's a summary from gpt-oss:120b Focused comparison –
|
| Method | Avg time (run 1) | Avg time (run 2) | Δ % (time) | Ops/sec (run 1) | Ops/sec (run 2) | Δ % (throughput) |
|---|---|---|---|---|---|---|
lru.keys |
0.002259 ms | 0.002168 ms | ‑4.0 % (faster) | 442 667 | 461 189 | +4.2 % |
lru.values |
0.018052 ms | 0.016303 ms | ‑9.7 % (faster) | 55 395 | 61 340 | +10.7 % |
lru.entries |
0.020361 ms | 0.018461 ms | ‑9.3 % (faster) | 49 114 | 54 167 | +10.3 % |
What the numbers mean
| Observation | Interpretation |
|---|---|
| All three methods are faster in the second run | The average execution time dropped 4‑10 %, translating into a 4‑11 % increase in operations per second. |
lru.values and lru.entries show the biggest gains |
Both are ~9‑10 % quicker. These are the most expensive of the three (they have to allocate and copy whole value/entry arrays), so any JIT warm‑up or reduced GC pressure in the second run yields a noticeable improvement. |
lru.keys improves modestly |
Keys are a lighter operation (just returning an array of stored keys), so the performance delta is smaller – a 4 % speed‑up is still respectable. |
| Std‑dev & max‑time stay similar | The variability (Std Dev) and worst‑case latency are in the same range for both runs, indicating the improvements are consistent rather than an outlier. |
| Implications for real‑world usage | If your application frequently enumerates the cache (e.g., for metrics, debugging, or bulk eviction), you’ll see a modest but measurable reduction in latency—roughly 0.2 ms per 10 k calls for keys and about 2 ms per 10 k calls for values/entries. In a high‑throughput service that performs many such enumerations per second, this can translate into a few percent overall CPU savings. |
Bottom line
lru.keys– 4 % faster, +4 % more ops/sec.lru.values– ~10 % faster, +11 % more ops/sec.lru.entries– ~10 % faster, +10 % more ops/sec.
The second benchmark run demonstrates a clear performance advantage for the three enumeration‑type methods, with the greatest benefit seen on the heavier values and entries calls. If your workload relies heavily on pulling full key/value lists from the LRU cache, you can expect a noticeable latency reduction and higher throughput in the second run.
Contributor
Author
|
Owner
|
that's the 🔬 Node.js Performance API Benchmarks
======================================
Node.js version: v24.13.0
Platform: darwin arm64
Date: 2026-01-14T15:34:53.784Z
🔬 LRU Performance Benchmarks
==============================
(Using CustomTimer for high-resolution function timing)
Running operations...
Phase 1: Initial cache population
Phase 2: Mixed operations
Phase 3: Cache eviction stress test
Phase 4: Clear operations
Phase 5: Additional API method benchmarks
⏱️ Performance Results
========================
┌─────────┬────────────────────────────────┬────────────┬────────────┬────────────┬────────────┬─────────────┬────────────┬──────────┐
│ (index) │ Operation │ Iterations │ Avg (ms) │ Min (ms) │ Max (ms) │ Median (ms) │ Std Dev │ Ops/sec │
├─────────┼────────────────────────────────┼────────────┼────────────┼────────────┼────────────┼─────────────┼────────────┼──────────┤
│ 0 │ 'lru.set (initial population)' │ 10000 │ '0.000181' │ '0.000041' │ '0.152792' │ '0.000125' │ '0.001954' │ 5539516 │
│ 1 │ 'lru.get' │ 10000 │ '0.000129' │ '0.000041' │ '0.093958' │ '0.000084' │ '0.001240' │ 7730305 │
│ 2 │ 'lru.set' │ 10000 │ '0.000108' │ '0.000041' │ '0.034500' │ '0.000084' │ '0.000489' │ 9267755 │
│ 3 │ 'lru.has' │ 10000 │ '0.000085' │ '0.000041' │ '0.031541' │ '0.000083' │ '0.000459' │ 11830665 │
│ 4 │ 'lru.keys' │ 10000 │ '0.002190' │ '0.001750' │ '0.061792' │ '0.001917' │ '0.002292' │ 456648 │
│ 5 │ 'lru.values' │ 10000 │ '0.016835' │ '0.014625' │ '0.087250' │ '0.015833' │ '0.003299' │ 59399 │
│ 6 │ 'lru.entries' │ 10000 │ '0.019046' │ '0.016208' │ '0.221500' │ '0.017750' │ '0.005037' │ 52505 │
│ 7 │ 'lru.delete' │ 10000 │ '0.000085' │ '0.000041' │ '0.039333' │ '0.000083' │ '0.000474' │ 11757748 │
│ 8 │ 'lru.set (eviction stress)' │ 10000 │ '0.000248' │ '0.000125' │ '0.077791' │ '0.000209' │ '0.000835' │ 4027318 │
│ 9 │ 'lru.clear' │ 10000 │ '0.000104' │ '0.000041' │ '0.167041' │ '0.000083' │ '0.001679' │ 9638220 │
│ 10 │ 'lru.setWithEvicted' │ 10000 │ '0.000217' │ '0.000083' │ '0.168291' │ '0.000167' │ '0.001942' │ 4598124 │
│ 11 │ 'lru.expiresAt' │ 10000 │ '0.000049' │ '0.000000' │ '0.009584' │ '0.000042' │ '0.000139' │ 20555238 │
└─────────┴────────────────────────────────┴────────────┴────────────┴────────────┴────────────┴─────────────┴────────────┴──────────┘
📈 Scalability Test
===================
Testing cache size: 100
Testing cache size: 500
Testing cache size: 1000
Testing cache size: 5000
Testing cache size: 10000
┌─────────┬───────┬────────────────┬───────────────────┬───────────────────┬───────────────────┐
│ (index) │ Size │ Set Total (ms) │ Set Per Item (ms) │ Get 1K Items (ms) │ Get Per Item (ms) │
├─────────┼───────┼────────────────┼───────────────────┼───────────────────┼───────────────────┤
│ 0 │ 100 │ '0.03' │ '0.0003' │ '0.13' │ '0.0001' │
│ 1 │ 500 │ '0.08' │ '0.0002' │ '0.07' │ '0.0001' │
│ 2 │ 1000 │ '0.15' │ '0.0002' │ '0.07' │ '0.0001' │
│ 3 │ 5000 │ '0.69' │ '0.0001' │ '0.07' │ '0.0001' │
│ 4 │ 10000 │ '1.22' │ '0.0001' │ '0.10' │ '0.0001' │
└─────────┴───────┴────────────────┴───────────────────┴───────────────────┴───────────────────┘
✅ Performance tests completed!
📋 Notes:
- Benchmarks: High-resolution timing with statistical analysis using CustomTimer (based on performance.now())
- Scalability Test: Shows how performance scales with cache size |
Owner
|
this is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.