Repository navigation
[PR] perf: index message lookups for fold image notes - #6612
Merged
ranxianglei merged 1 commit intoNov 14, 2026
Merged
Conversation
Owner
|
Superseded by #6677 (merged as Landed into master via the real merge commit The fix for #6610 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix. |
This was referenced Nov 14, 2026
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 #6610
Problem
After creating a block,
applyRangeslooks up each direct message withview.find(...)before producing image recovery notes. Plain-text messages take this path too. Folding the first 8,000 messages of a 12,000-message history performs 32,004,000 ID comparisons in this step, synchronously on the proxy event loop.Change
Build one local ID-to-message index when the first new block with direct messages needs it. Keep the first occurrence of each ID to preserve
Array.findbehavior, and visit direct IDs in their original order. The selected view remainscompressMessages ?? messages; existing blocks and new blocks without direct IDs do not build an index.The lookup phase becomes O(N + K) for N source messages and K direct IDs. The index adds O(N) temporary references for that call. Image descriptions, recovery refs, summary bytes, eligibility, net-benefit accounting and the other compression steps retain their existing behavior.
Measured effect
scripts/bench-fold-image-notes.tsmeasures the complete realapplyRangescall, using the real kernel and a successful 8,000-message fold over 12,000 valid user/assistant text messages. The serialized input is 5,035,781 bytes.Three fresh-process pairs, alternating execution order, one warm-up and three measured calls per process:
Across the nine measured calls per variant, the pooled median is 2,676.51 → 2,373.06 ms, an 11.3% reduction in this local workload. Every measured large-workload receipt, summary, covered-ID list and compressed-token total has the same SHA-256:
8fa459ff698fcd2a496fdd1bd814fcab1abe4575014371719c72f369c88f7592.The small control (16 messages, six folded, 53,285 serialized bytes; 20 measurements per process) stays in the low-millisecond range: pooled 1.976 → 1.744 ms. CPU and peak RSS ranges overlap; this change targets repeated lookup work and makes no memory-reduction claim. Results depend on machine and workload.
Reproduction after building dependencies:
Copy the unchanged benchmark into a worktree at the base revision to compare.
Validation
git diff --checkpass.codex-cli 0.167.0-alpha.4, but the local upstream at127.0.0.1:8199is unreachable; the live four-phase Codex suite was not run. The full-suite verdict remains with hosted CI on this head.Baseline:
e1f31ad9d5b47500362699a9867819b861c7de96(0.1.213), Node v24.22.1, repository test/storage preloads.Prior work
All-state searches and contributor history found no existing fix at this step. #2043 indexes summary-carrier evidence in
stripKernelSummaries; #6242 removes storage media-array copies. #2022 introduced image recovery, and #3726 concerns visual summary quality. Their mechanisms are separate.Suggested triage:
p2,scope/kernel; Topic C — compression behavior. Source changes are host-only; nokernel/, configuration or persistence changes.