refactor(app): avoid deep equality in timeline row reconciliation - #48435
refactor(app): avoid deep equality in timeline row reconciliation#48435Priyansh4444 wants to merge 2 commits into
Conversation
Compare the nine timeline row variants field by field instead of calling Equal.equals for every row on every stream delta. The PartGroup comparison now comes from session-ui (message-part-groups) instead of a local copy, and DiffSummary.diffs still uses Equal.equals. Add a unit test asserting the comparator agrees with Equal.equals for every variant pair, so it runs in the normal CI unit suite.
6b7255a to
f8ad7c1
Compare
|
The comparator here used to be a 15 byte stub that called Effect's The group check is shared with Numbers from the benchmark, which runs the real modules over a 1,288 row timeline:
Why this path matters: the timeline rebuilds its row list in a memo whenever messages or parts change, so every streamed update compares the whole timeline with the previous one. The fixture does 1,288 comparisons per update. Before, Effect's equal/hash code held 34.4% of JS samples; after, none. I tested fixing Effect instead. Skipping the hash check inside Each build runs in its own process. When two builds share one process, the engine's optimizations for one can distort the other's numbers. An AI agent wrote this change while following a documented process. I reproduced the benchmark and tests myself; the browser numbers come from the agent's run. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
I am sorry if this ends up being burden review; but this was what my agent found and it seemed correct especially the benching aspect of it! Correct me if I am wrong. And thank you for taking the time to review it! This also does sacrifice some readability for performance. |
Issue for this PR
Closes #48434
Type of change
What does this PR do?
reuseTimelineRowscompares every incoming timeline row against the previous one withEqual.equals, so Effect hashes and walks the whole row, including everyPartGroupref, on each streamed delta. This replaces that call with a comparator that switches on the row's_tagand compares only that variant's fields. ThePartGroupcheck is shared withsession-uiinstead of copied, andDiffSummary.diffsstill usesEqual.equals.How did you verify your code works?
packages/app/src/pages/session/timeline/timeline-row-equality.test.tsasserts the new comparator agrees withEqual.equalsfor every row variant pair. It runs in the normal unit suite, so CI covers it on every PR.bun run test:unit726 pass.bun test ./e2e/performance/unit43 pass.perf staton the same harness: 137.6B to 13.2B retired instructions.compareObjectsmoved a one-off benchmark by about 3%, so the fix stays local.Screenshots / recordings
Not a UI change. Rendered output parity was checked in the browser run and the unit tests.
Checklist