Repository navigation
Match file-change rows by path index instead of scanning every row - #7834
Closed
cleanunicorn wants to merge 1 commit into
Closed
cleanunicorn wants to merge 1 commit into
cleanunicorn wants to merge 1 commit into
Conversation
matchFileRows searched all of a record's file rows for every change in a fileChange event, so each started/updated/completed event cost O(files^2). Index the existing rows by match key once per event and take the earliest unclaimed row per key, which keeps the same earliest-row rule in O(files). A timeline build with one 2,000-file change drops from 28 ms to 3 ms, and a 4,000-file change from 127 ms to 6 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Thanks for the pull request, @cleanunicorn. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change. Contributor approval. bb reviews pull requests only from approved contributors, and you are not on the list yet. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to your pull request, and explain what it changes and why. A maintainer then adds you to the list and reopens the pull request. See CONTRIBUTING.md for details. |
ymichael
added a commit
that referenced
this pull request
Nov 19, 2026
🚨 **SLOP COP** 🚨 · `new-issue-autopilot` ## Human comments ## What was wrong Timeline projection searched every accumulated file row separately for each incoming file change, including rows already claimed in the same event. This made large file-change events quadratic in their file count. The behavior reproduces on trusted main in two clean checkouts: a sixteenfold increase in file count costs about 183× as much with reversed completion order. Reproduction and root-cause report: https://get-bb.github.io/reports/issues/7833.html ## What changed - Index existing row positions by historical path once per event, with descending candidate lists that lazily discard claimed rows. - Select the earliest eligible row across both incoming paths, preserving historical aliases, duplicate paths, stale-row reappearance, and the rule that a new row cannot be claimed again in the same event. - Add a public timeline scaling regression and an identity regression for competing rename paths and duplicate files. - All changes stay in `packages/thread-view`; no dependency, lockfile, generated-file, persisted-data, public API, protocol, CLI, or UI changes. - Changed-line count: **193 total text lines across 3 files** (188 additions, 5 deletions), measured with `git diff --numstat origin/main`. Production: 27 additions and 5 deletions; tests: 161 additions. No binary changes. ## How you verified - Added the scaling regression before changing production code. On unchanged main, its reversed-order case fails: ratio **183.44**, expected below **64**. A second clean checkout fails the same assertion at **182.13**. The unchanged-order control passes the intentionally generous threshold. - After the fix, the focused scaling cases pass at **8.11×** and **19.18×** for a sixteenfold file-count increase; 4,096-file builds take approximately **13–15 ms**, versus **146–401 ms** before. - The identity regression passes before and after the fix. - `pnpm exec turbo run test --filter=@bb/thread-view -- test/file-change-scaling.test.ts test/build-thread-timeline.test.ts --silent=false`: **86 passed**. - `pnpm exec turbo run test typecheck lint:type-aware --filter=@bb/thread-view`: **545 tests passed**, typecheck and type-aware lint passed. - `pnpm exec turbo run test --filter=@bb/server -- test/timeline-history test/services/threads/timeline-in-turn-window.test.ts test/services/threads/timeline-event-budget.test.ts test/public/public-thread-timeline-work-rows.test.ts`: **58 passed, 2 skipped**. The history-replay cases require `BB_TIMELINE_HISTORY_DB`, which was not supplied; no real application data was used. - `pnpm exec oxfmt` on the three changed files and `git diff --check` pass. - PR #7834 is closed and unmerged; its branch was not checked out or run. No linked open PR existed when this change was prepared. Fixes #7833 > AGENT GENERATED <!-- slopcop:rule=new-issue-autopilot run=run_6gq8iyw8mwno7ead sha=issue-7833 kind=summary --> --------- Co-authored-by: SawyerHood <[email protected]> Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Human comments
What was wrong
matchFileRows(packages/thread-view/src/item-records.ts) matched each change in a fileChange event against the item's earlier rows. It ranrecord.fileRows.findIndex(...), which checksrow.matchKeys.some((key) => matchKeys.includes(key))for every row. That makes every started, updated or completed fileChange event O(files²). A timeline build with one 2,000-file change took 28 ms, and a 4,000-file change took 127 ms.What changed
matchFileRowsmaps each match key to the indexes of the rows that existed before the event, once per event.pathormovePath. Rows created during the event are claimed when created, and a row'smatchKeyschange only once it is claimed, so building the index once per event sees the same candidates as the old scan.Each figure is one
buildThreadTimelineFromEventscall overturn/started,item/startedanditem/completedfor one fileChange item: best of 5 after a warm-up, Node 24, Linux.How you verified
matches each later file change to the earliest unclaimed row sharing a path. It covers duplicate paths, amovePaththat matches an earlier row, reordering, and new files. It passes before and after, so the matching rule is unchanged.matches a large file change's rows in time linear in its file count. It is a CPU-time ratio guard in the style oftool-call-parsing-performance.test.ts, comparing 500 and 4,000 files. It fails before the change (expected 337609 to be less than 167280) and passes after.pnpm exec turbo run typecheck lint test --filter=@bb/thread-view: 544 tests pass.matchFileRowsover 200,000 event sequences found no difference infileRowIndexes, rowkeyormatchKeys. The sequences mixed duplicate paths,movePathrenames, reorders, and added or dropped files.apps/server, the timeline suites that build through this projection pass: 4 files ran, 68 tests passed. These includetimeline-event-budget,timeline-in-turn-windowandtest/timeline-history. 5 files skipped: the provider-corpus suites need a private corpus (BB_PROVIDER_CORPUS_*), which I don't have.Fixes #7833
🤖 Generated with Claude Code