Skip to content

Chat: the composer dock stops searching the whole thread on every com… - #14585

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
Sneakr:perf/composer-dock-children
Oct 22, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
Sneakr:perf/composer-dock-children

Conversation

@Sneakr

@Sneakr Sneakr commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Every time the composer changes height (each new line of a multi-line draft), the composer dock's ResizeObserver looked up the thread footer with viewport.querySelector(":scope > .aui-thread-viewport-footer"). In Chromium (Unsloth Web in Chrome/Edge, Unsloth Desktop on Windows) that query visits every element in the thread, so its cost grows with the chat. This PR walks the viewport's direct children instead, which returns the same element.

This removes thread-sized work from multi-line typing in long chats. Per-keystroke latency is unchanged within measurement noise, so this is a CPU saving.

What changes

  • thread.tsx: a small childWithClass(parent, className) helper replaces the two :scope > lookups in ThreadComposerDock (the thread viewport next to the dock, and the footer inside it).
  • tests/composer-dock-column-lookup.test.ts: four tests. The helper returns the first direct child with the class, skips non-HTML children, never matches a nested descendant, and the dock uses it instead of a selector.
  • Startup bundle: +88 B raw / +53 B transfer, inside the current budget, so the budget is unchanged.

Measurements

Typing in a long live chat. A code-heavy chat of about 62K elements, typing ten composer-growing lines (130 keys). Playwright Chromium 148, headless Linux, 4 sessions × 2 rounds per arm.

main this PR
Script, 1× CPU 739 ms 539 ms (−27%)
Total task, 1× CPU 1,754 ms 1,536 ms (−12%)
Script, 4× CPU 2,338 ms 1,914 ms (−18%)
Total task, 4× CPU 5,198 ms 4,901 ms (−6%)
Plain typing (43 keys), script 1× / 4× 114 / 457 ms 116 / 450 ms

The lookup was 196 ms of self time in the 1× probe on main. Plain typing never reaches this code. Per-keystroke latency from trace EventTiming is within the rig's noise: multi-line p98 at 1× is 32.0 vs 30.6 ms.

#13919 benchmark harness. Windows Chrome 155, 240 Hz display, saved conversation and answer-only proxy, 1× and 4× CPU, 3 runs per cell. Every table is within run-to-run noise of main. Whole-session renderer time, main vs this PR:

Workload CPU main this PR
Saved conversation 1× 14.60 s 14.53 s
Saved conversation 4× 54.13 s 53.57 s
Answer-only 1× 9.55 s 9.46 s
Answer-only 4× 38.27 s 38.38 s

Testing

  • npm test: 13,396 pass, 0 fail.
  • npm run typecheck passes.
  • ESLint: thread.tsx findings are identical to main; the new test file is clean.
  • npm run bundle:check is within budget.
  • The new lookup returns the same element as the old selectors in Chromium, Firefox and WebKit.

Follow-up: walk from the last child

The helper now walks back from lastElementChild. The footer follows every message row, so a forward walk costs one check per row, and in current Chromium and Firefox that was slower than the :scope > selector it replaced. Walking back reaches the footer on the first check and the viewport in two. Per lookup on a 62K-element thread (200 rows, median of 21 samples x 200 calls, headless Linux):

Engine :scope > (main) forward walk walk from the end
Chromium 156 1.5 us 36.5 us ~0 us
Firefox 157 ~0 us 20 us ~0 us
WebKit 27.2 1945 us 15 us ~0 us

All three lookups return the same element in all three engines, including when a nested descendant carries the footer class. A new test asserts that finding the footer after 500 rows checks a single child.

…poser resize

The dock's ResizeObserver ran viewport.querySelector(":scope > .aui-thread-viewport-footer")
every time the composer changed height (each new line of a multi-line draft). In Chromium
that query visits every element of the thread, so its cost grows with the chat. Walking the
viewport's direct children returns the same element in Chromium, Firefox and WebKit.

Measured on the unslothai#13919 benchmark harness (Windows Chrome 155, 240 Hz display, both fixtures,
1x and 4x CPU, 3 runs per cell): every table is within run-to-run noise of main.

Measured in a live code-heavy chat of about 62K elements (Playwright Chromium 148, headless,
Linux, 4 sessions x 2 rounds per arm): typing ten composer-growing lines (130 keys) spends
739 -> 539 ms of script at 1x CPU and 2,338 -> 1,914 ms at 4x; total task time -12% and -6%.
The query was 196 ms of self time in that probe on main. Plain typing does not reach this
code and is unchanged; per-keystroke latency to the presented frame stays within the rig's
noise at both CPU rates.

Startup bundle: +88 B raw / +53 B transfer (6,879,345 -> 6,879,433 B raw, 2,071,823 ->
2,071,876 B transfer against 5a955ef, Node 24, 97 chunks), inside the current budget
(156 B raw / 136 B transfer to spare), so the budget is unchanged.
@Sneakr
Sneakr requested a review from danielhanchen as a code owner October 22, 2026 02:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T12:26:20.550187Z 5967dbc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sneakr

Sneakr commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 520bfd50cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen danielhanchen self-assigned this Oct 22, 2026
The footer follows every message row, so a forward walk over the viewport's
children costs O(rows), which in Chromium and Firefox is slower than the
:scope > selector it replaced. Walking back from lastElementChild reaches
the footer first and the viewport in two steps.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

3 similar comments
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5af01d2b5f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: ff179a5e33

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Conflicts:
#	studio/frontend/scripts/check-bundle-budget.ts
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 5967dbc503

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 8920e38 into unslothai:main Oct 22, 2026
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.

2 participants