Skip to content

Faster memory limiter and blocks mechanism#355

Merged
animir merged 7 commits intomasterfrom
faster-memory-and-blocks
Mar 14, 2026
Merged

Faster memory limiter and blocks mechanism#355
animir merged 7 commits intomasterfrom
faster-memory-and-blocks

Conversation

@animir
Copy link
Copy Markdown
Owner

@animir animir commented Mar 10, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 MemoryStorage internal _storage from object to Map and adjust access patterns (get/set/delete).
  • Convert Record.expiresAt from Date to a numeric Unix timestamp (ms) and update related tests.
  • Convert BlockedKeys internal _keys from object to Map and 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

  • msBeforeExpire no longer removes expired keys from _keys. This can leave stale entries in memory indefinitely (unless collectExpired() happens to run), causing _keys.size to grow and making future operations slower. Consider deleting the key when it is expired (and optionally triggering collectExpired() 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.

@animir animir merged commit fe6b271 into master Mar 14, 2026
10 checks passed
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.

2 participants