Skip to content

fix(infra): lazy prune in DedupeCache to resolve Discord 33-122s message delays#1264

Open
BingqingLyu wants to merge 2 commits intomainfrom
fork-pr-52762-fix-discord-message-listener-perf
Open

fix(infra): lazy prune in DedupeCache to resolve Discord 33-122s message delays#1264
BingqingLyu wants to merge 2 commits intomainfrom
fork-pr-52762-fix-discord-message-listener-perf

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Fixes openclaw#4453

Root Cause

The dedupe fix (openclaw#51950) added recentInboundMessages.check() to the
Discord message handler. check() called prune() 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 when cache.size > maxSize
  • src/infra/map-size.ts — fixed corrupted duplicate code + rewrote
    pruneMapToMaxSize to delete in a single forward pass

Testing

  • src/infra/dedupe.test.ts done (5 tests)
  • src/infra/map-size.test.ts done (2 tests)
  • extensions/discord/src/monitor/message-handler.queue.test.ts done (11 tests)

Erprabhat8423 and others added 2 commits March 23, 2026 14:06
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
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.

[Bug]: Discord MessageListener performance regression (33-122s delays)

2 participants