fix(infra): lazy prune in DedupeCache to resolve Discord 33-122s message delays#1264
Open
BingqingLyu wants to merge 2 commits intomainfrom
Open
fix(infra): lazy prune in DedupeCache to resolve Discord 33-122s message delays#1264BingqingLyu wants to merge 2 commits intomainfrom
BingqingLyu wants to merge 2 commits intomainfrom
Conversation
The dedupe fix in openclaw#51950 introduced recentInboundMessages.check() in the Discord message handler. This called prune() on every single message, which did a full linear scan of up to 5000 cache entries on each invocation. On active Discord servers, this blocked the event loop for tens of milliseconds per message, stacking up to the 33-122s delays reported in openclaw#4453. Also fixed map-size.ts which had corrupted duplicate code. Changes: - dedupe.ts: only call prune() when cache.size exceeds maxSize - map-size.ts: rewrite pruneMapToMaxSize to delete in a single pass instead of calling map.keys().next() in a while loop Fixes openclaw#4453
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.
Fixes openclaw#4453
Root Cause
The dedupe fix (openclaw#51950) added
recentInboundMessages.check()to theDiscord message handler.
check()calledprune()on every message,which did a full linear scan of up to 5000 cache entries each time.
On active servers this blocked the event loop cumulatively, producing
the exact 33-122s delays reported in the issue.
Changes
src/infra/dedupe.ts— only prune whencache.size > maxSizesrc/infra/map-size.ts— fixed corrupted duplicate code + rewrotepruneMapToMaxSize to delete in a single forward pass
Testing