Faster memory limiter and blocks mechanism#355
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the in-memory components by switching key containers from plain objects to Map and by representing expiration times as numeric timestamps to reduce Date object overhead.
Changes:
- Convert
MemoryStorageinternal_storagefrom object toMapand adjust access patterns (get/set/delete). - Convert
Record.expiresAtfromDateto a numeric Unix timestamp (ms) and update related tests. - Convert
BlockedKeysinternal_keysfrom object toMapand update tests accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/component/MemoryStorage/Record.test.js | Updates expectations to match expiresAt now returning a number timestamp. |
| test/component/BlockedKeys/BlockedKeys.test.js | Updates tests to use Map.size and removes assertions tied to the old object-based implementation. |
| lib/component/MemoryStorage/Record.js | Changes expiresAt storage to numeric timestamps; updates value casting. |
| lib/component/MemoryStorage/MemoryStorage.js | Migrates storage to Map and switches expiration arithmetic to use Date.now(). |
| lib/component/BlockedKeys/BlockedKeys.js | Migrates blocked key tracking to Map and adjusts collection logic. |
Comments suppressed due to low confidence (1)
lib/component/BlockedKeys/BlockedKeys.js:56
msBeforeExpireno longer removes expired keys from_keys. This can leave stale entries in memory indefinitely (unlesscollectExpired()happens to run), causing_keys.sizeto grow and making future operations slower. Consider deleting the key when it is expired (and optionally triggeringcollectExpired()periodically) before returning 0.
msBeforeExpire(key) {
const expire = this._keys.get(key);
if (expire && expire >= Date.now()) {
const now = Date.now();
return expire >= now ? expire - now : 0;
}
return 0;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…aster-memory-and-blocks
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.
No description provided.