Skip to content

perf(ui): a ChoiceBar measures only when what it measures changes, compared by structure - #4325

Merged
luke-agent[bot] merged 2 commits into
mainfrom
luke/choice-bar-fold-measure
Oct 21, 2026
Merged

luke-agent[bot] merged 2 commits into
mainfrom
luke/choice-bar-fold-measure

Conversation

@charleslpan

@charleslpan charleslpan commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

This is a follow-up to #4296. Charles asked for a profile with the long "Neon Realtime" transcript open, then for the keys to be cleaned up.

What the profile showed

The build was bae007ad2, which includes #4296. The transcript had about 33k elements, and the window was in use. Over 15 s the main thread was busy 10.0 s, with 1,323 style recalcs.

The largest single cost was useFoldTogether in choice-bar.tsx, at 1.06 s of every 15 s:

  • The bug: its useLayoutEffect(measure) had no dependency list, so it read every option's box and getComputedStyle(bar) after every draw. Each read forced a style and layout pass over the whole window.
  • Why it ran so often: the agent tab's toolbar bar redraws with every transcript page.

What changed

  • Fold: it measures as it first draws, whenever how the bar draws its options or any option's glyph, name or count changes, and whenever the bar or an option resizes, as before. The ResizeObserver re-observes the options whenever they change.
  • Keys: the thumb (from perf(panel,ui): stop forcing a whole-window layout on every draw and DOM change #4296) and the fold no longer decide "did it change" with a string joined from fields, which AGENTS.md rules out.
    • Each is now a typed value (OptionsPlaced, OptionsNamed).
    • useKept keeps the previous value while every part of it is equal, using keepIdentity from @luke/wire, so the effects run only when it changes.
  • applyMessagesPage: my hand-written deep compare from perf(panel,ui): stop forcing a whole-window layout on every draw and DOM change #4296 is replaced by keepIdentity. A message heard again unchanged is still the one held, and a message that grew now also keeps the parts that didn't change.

Tests

  • A new test grows one option's name with nothing resized and checks that the bar folds. It fails if named is dropped from the measure effect's dependencies.
  • The thumb test from perf(panel,ui): stop forcing a whole-window layout on every draw and DOM change #4296 fails if placed is dropped from the thumb's dependencies.
  • The test that a re-sent page keeps the held messages still passes.
  • choice-bar, coding-agent-wire, use-agent-transcript and transcript-copy pass, and so do the ui and features typechecks, Biome and oxlint.

Made with Luke

…hey change

useFoldTogether measured its options after every draw: a layout effect with
no dependency list read every option's box and getComputedStyle, each
forcing a style and layout pass over the whole window. The agent tab's
toolbar bar draws again with every transcript page, so a profile with a
long transcript open put it at 1.06 s of every 15 s, the largest single
cost left after #4296.

It now measures as it first draws, whenever the options' names, glyphs, or
counts or the bar's look change, and whenever the bar or an option
resizes. The resize observer follows the options afresh as they change.

Co-authored-by: luke-agent[bot] <339870089+luke-agent[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
luke-web Ready Ready Preview Oct 21, 2026 2:56pm UTC

Request Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

…essages by structure

ChoiceBar's thumb and fold decided whether to measure again by a string
joined from the bar's look and its options, which AGENTS.md rules out. Each
is now a typed value, kept from the draw before while every part of it is
equal (useKept, over @luke/wire's keepIdentity), so its effects run only
when it changes.

applyMessagesPage compared a message heard again with a deep compare of its
own. It now uses keepIdentity too, so a message that grew keeps every part
that didn't change, and one heard again unchanged is the one held.

Co-authored-by: luke-agent[bot] <339870089+luke-agent[bot]@users.noreply.github.com>
@luke-agent luke-agent Bot changed the title perf(ui): a ChoiceBar folding together measures its names only when they change perf(ui): a ChoiceBar measures only when what it measures changes, compared by structure Oct 21, 2026
@luke-agent
luke-agent Bot added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit 04a4a10 Oct 21, 2026
11 of 12 checks passed
@luke-agent
luke-agent Bot deleted the luke/choice-bar-fold-measure branch October 21, 2026 14:54

This branch was successfully deployed

1 active deployment
Preview — f809a095 Deployed Oct 21, 2026 by vercel[bot]
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.

1 participant