Skip to content

New random fixes#399

Closed
avoidwork wants to merge 2 commits intomasterfrom
newRandomFixes
Closed

New random fixes#399
avoidwork wants to merge 2 commits intomasterfrom
newRandomFixes

Conversation

@avoidwork
Copy link
Owner

No description provided.

- entries() and values() previously called get() during iteration which moved items during traversal
- Changed to build a lookup map first for O(1) access without mutating LRU order
- Updated @param docs to clarify optional keys parameter behavior
- Removed unnecessary comments
- All 53 tests pass with 100% coverage
@avoidwork avoidwork self-assigned this Mar 5, 2026
@augmentcode
Copy link

augmentcode bot commented Mar 5, 2026

🤖 Augment PR Summary

Summary: Refines LRU.entries() and LRU.values() iteration behavior to avoid mutating recency order during read-only enumeration.

Changes:

  • Adjusts JSDoc for `entries()`/`values()` to describe optional `keys` input (defaults to all keys when omitted).
  • Reworks `entries()` to snapshot current list order into a temporary lookup table and return `[key, value]` pairs without calling `get()`.
  • Reworks `values()` similarly to return values without calling `get()`.

Technical Notes: Both methods now walk the internal linked list once to build a key -> value map, avoiding per-key get() calls (and thus avoiding access-induced LRU updates).

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

- keys() was calling String(x.key) which added unnecessary overhead
- No functional benefit since map lookups use original key types
- Improves GET throughput by ~2.6%
@avoidwork
Copy link
Owner Author

augment review

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

let x = this.first;

while (x !== null) {
entryMap[x.key] = x.value;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using entryMap[x.key] = x.value means entries()/values() no longer go through get(), so TTL expiration won’t be enforced (expired items won’t be deleted and may be returned as if still valid). If TTL is expected to apply to these accessors too, this changes observable behavior for caches with ttl > 0.

Severity: high

Other Locations
  • src/lru.js:458

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@avoidwork avoidwork closed this Mar 5, 2026
@avoidwork avoidwork deleted the newRandomFixes branch March 5, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant