You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Perf][grounded-shop-assistant]: session eviction sorts all 5000 sessions on every new session once full #494
At MAX_SESSIONS = 5000, that's an array allocation plus an O(n log n) sort on the request path of every first message, which is exactly when the server is busiest (the map is full).
A JS Map iterates in insertion order. If a session is moved to the end whenever it's touched (delete then set), the first key is always the least-recently-used one, and eviction becomes O(1):
// on get(existing) and save():sessions.delete(session.id);sessions.set(session.id,session);// evict:constoldestId=sessions.keys().next().value;if(oldestId!==undefined)sessions.delete(oldestId);
That also makes lastSeen only needed for the TTL sweep.
Expected Behavior
Evicting a session is O(1).
Suggested fix
As above. If the session-store tests from #493 land first, they'll confirm eviction order doesn't change.
Activity