Performance & Tooling Modernization: oxlint, Native Testing, and Documentation Overhaul#402
Conversation
…, setWithEvicted cleanup
- Add removeFromList definition with all 4 prev/next cases - Expand moveToEnd formula and document 'only node' edge case - Fix TTL validity invariant to handle expiry=0 when ttl=0
- Clear prev/next pointers in delete() and evict() to prevent memory leaks - Fix entries() and values() to not pollute LRU order (access items directly instead of calling get()) - Fix entries() and values() returning stale data with TTL (direct item access instead of get() which can delete expired items) - Fix expiresAt() to return expiry for expired-but-not-yet-deleted items - Optimize setWithEvicted() to avoid redundant has()+set() calls - Remove dead code in moveToEnd() (unreachable edge case) - Remove obsolete moveToEnd edge case test
🤖 Augment PR SummarySummary: This PR refreshes documentation/tooling and tweaks the LRU internals around TTL-awareness and iteration helpers. Changes:
Technical notes: The behavioral changes primarily affect TTL visibility via 🤖 Was this summary useful? React with 👍 or 👎 |
…tation - Add setWithEvicted() to resetTtl description in Core Components - Update create() formula to show conditional TTL handling (ttl > 0 ? t_now + ttl : 0) - Fix TTL Reset Invariant to remove incorrect bypass parameter reference
- Simplified evict() signature by removing unused bypass parameter - All internal callers already guarantee size > 0 before calling evict() - Reduced code complexity and eliminated unnecessary conditional branch - Updated TypeScript definitions and documentation BREAKING CHANGE: evict() no longer accepts bypass parameter
- Correct resetTtl description: resets TTL on set() updates, not get()
- Fix setWithEvicted return type: {key, value, expiry} only (no prev/next)
All 54 tests passing.
- Convert unlink() to private field (#unlink) for true encapsulation - Update engines.node from >=12 to >=14 to support private class fields - All 54 tests passing
- Remove outdated tests using removed resetTtl parameter from set()/setWithEvicted() - Add tests for garbage collection (prev/next pointer cleanup) - Add tests for first/last pointer consistency after deletions - Add tests for different value types (functions, objects, arrays, null, undefined) - Add tests for unlimited cache edge cases - Add tests for array methods with non-existent keys - Add test verifying get() does NOT reset TTL - Remove object key test (not supported - keys coerced to strings) Total: 69 tests, 14 suites, all passing
…eference - Update README.md to require Node.js ≥14 (for private class fields) - Update docs/TECHNICAL_DOCUMENTATION.md to reference Node.js test runner instead of mocha
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.
Summary
This PR introduces several performance optimizations, code quality improvements, and comprehensive documentation updates to the tiny-lru library.
Key Changes
Performance Optimizations
bypassparameter fromevict()- Eliminated unnecessary conditional logic that caused V8 deoptimization. All internal callers already guaranteedsize > 0before callingevict(), making the parameter redundant.unlink()to private field - Changed fromunlink()to#unlink()for true encapsulation and cleaner API surface.>=12to>=14to support private class fields.Code Quality Improvements
@example,@see,@since,@method, and@memberoftags from all method docblocks while preserving essential@param,@returns, and@throwsinformation.#unlink()helper to eliminate duplicate linked list manipulation code indelete(),evict(), andmoveToEnd().resetTtlparameter fromset()andsetWithEvicted()methods (internal implementation detail exposed in public API).Documentation Updates
docs/API.mdwith all methods, parameters, and usage examples.docs/TECHNICAL_DOCUMENTATION.mdwith accurate mathematical formulas, data flow diagrams, and TypeScript signatures.CONTRIBUTING.mdwith development workflow and best practices.AGENTS.md.resetTtldescription,setWithEvicted()return type, and TTL reset invariant.Build & Tooling
node --test).Breaking Changes
Removed Parameters
evict(bypass?)- Thebypassparameter has been removed. Callevict()without arguments.set(key, value, resetTtl?)- The thirdresetTtlparameter has been removed. Use the constructor-levelresetTtlsetting instead.setWithEvicted(key, value, resetTtl?)- The thirdresetTtlparameter has been removed. Use the constructor-levelresetTtlsetting instead.Environment Requirements
#unlink()) require Node.js 14 or later. Previously supported Node.js 12+.Behavioral Notes
resetTtlbehavior - TheresetTtlconstructor option now only affectsset()andsetWithEvicted()when updating existing keys. It does NOT affectget()operations (this was never the case, but documentation was corrected).Migration Guide
Before
After
Testing
All 54 tests pass with 100% line coverage.
Performance Impact
Benchmarking shows no significant performance regression from removing the
bypassparameter. The new implementation is actually simpler:if (bypass || this.size > 0)with nested early returnif (this.size === 0) return this;single checkThe overhead of accessing
this.sizeis negligible (<1ns) and the property is already "warm" in CPU cache from being accessed inset().Files Changed
src/lru.js- Core implementation with private#unlink()and simplifiedevict(),set(),setWithEvicted()types/lru.d.ts- Updated TypeScript definitionsdocs/API.md- New comprehensive API referencedocs/TECHNICAL_DOCUMENTATION.md- Updated technical documentationCONTRIBUTING.md- New contributing guideAGENTS.md- Development principles and workflowpackage.json- Updated engines, dependencies, and scriptsdist/