Skip to content
Discussion options

You must be logged in to vote

Hey, I've dealt with almost the exact same issue on a high-traffic service. The raw Map with a cleanup interval is a losing battle at that scale; you're inserting faster than you can evict.

The fix that worked for me was two things:

First, ditch the Map entirely and use an LRU cache with a hard size cap. I switched to lru-cache and the heap flatlined immediately. It evicts lazily on access instead of scanning on every tick, so it's O(1) and memory-bounded by design:

import { LRUCache } from 'lru-cache';

const rateLimiter = new LRUCache({

  max: 100_000,  // hard cap, evicts oldest automatically

  ttl: 60_000,

  ttlAutopurge: false,

});

Second, and this matters since you're on ECS; ea…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by liya-daisuki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development source:ui Discussions created via Community GitHub templates
2 participants