Skip to content

Studio: publish the thread rows' role before their first style read - #17588

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
wasimysaid:fix/thread-row-role
Nov 13, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
wasimysaid:fix/thread-row-role

Conversation

@wasimysaid

@wasimysaid wasimysaid commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Scrolling a long chat got slower after #17504 merged. The cause is when the thread window writes role="article" (and the ordinals) onto the rows: in the commit's layout effect, after the anchor reads had already computed the new rows' style. The stylesheet has selectors on [role], so each newly mounted row was restyled a second time, and while scrolling the window mounts rows on almost every step.

This publishes the role and ordinals in an insertion effect instead: after React has inserted the rows and before anything reads their style, so each row is styled once. The markup is unchanged: rows carry role="article", aria-posinset and aria-setsize while the thread is windowed and none of them when it is fully mounted, exactly as on main.

Numbers

Window gate's thread (400 agent-style messages), headless Chromium, the same wheel sweep (250 steps up, 120 down), medians of 5. Main-thread time from CDP Performance.getMetrics over the sweep.

xychart-beta
    title "Style recalculation during the sweep, ms (lower is better)"
    x-axis ["main", "this PR", "no role at all"]
    y-axis "ms" 0 --> 2800
    bar [2533, 1731, 1736]
Loading
main this PR no role at all
Style recalculation 2,533 ms 1,731 ms 1,736 ms
Main-thread task time 10,708 ms 9,980 ms 10,159 ms
p95 frame gap 35.7 ms 29.7 ms 30.2 ms
Worst frame 47.8 ms 40.4 ms 39.9 ms
Window commits, rows mounted same same same

main measured twice for noise: 2,533 and 2,514 ms of style recalculation. With the role gone entirely the sweep costs the same as with this change, so what cost was the late write and not the role. Commit by commit over the 24 commits that made up #17504, style recalculation was flat at about 1,760 ms up to 2d804f1, which added the role write, and flat at about 2,450 ms from there on.

WebKitGTK (the Linux app) spends a larger share of its frame on style recalculation than Chromium does, so this should be felt more there; not measured in the native app for this PR.

Tests

  • progressive-mount-glue.test.ts: the role and ordinals are published in an insertion effect, before the layout effect's anchor reads.
  • playwright_thread_window.py: every windowed row carries role="article", the role its ordinals need. Passes in Chromium and Firefox.
  • Frontend unit suite and the thread browser gates (thread window, long-thread gate, heavy thread, long-chat renders, find in page, chat autoscroll, progressive rows, stream pacing, user message time, non-modal menus, Firefox leg) run locally.

Related: #17504. This does not address the streaming cost studiobench reported after a scroll during generation; I could not reproduce it outside the real app, and the role write made no difference to streamed-reply cost in my runs.

Before / after (parity)

Two isolated Studio installs, merge base 6c15abd99 against this PR, the same 300-message chat read at its bottom and at its top. The claim is that nothing visible changes, and the scene facts match on both sides: 11 mounted rows and 1,857 elements at the bottom with Reply marker R0149 in view, 19 rows and 2,257 elements at the top with Prompt marker P0000 in view, every windowed row carrying aria-setsize 300.

Bottom of the chat, before and after: identical

Top of the chat, before and after: identical

…fter mount

The thread window gave every row role="article" in publishOrdinals, after the row had
mounted. The stylesheet has selectors on [role], so each row was restyled a second time,
and while scrolling the window mounts rows on almost every step: over the window gate's
wheel sweep (400 messages, Chromium) style recalculation went from about 1,760 ms to
2,530 ms and the p95 frame gap from 29 to 36 ms, from the commit that added the write.

The user, assistant and edit roots now render the role, and the window never writes it.
Same sweep: 1,683 ms of style recalculation and a 28.7 ms p95 frame gap; with no role at
all it is 1,736 ms, so the role itself costs nothing. Rows carry the role in every thread
now, not only while windowed.

The window gate checks that every row carries the role and that no row's role is written
after it mounts during the sweep (397 writes on main).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T11:51:33.880497Z e970f0d 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e9a0123277

ℹ️ 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

Parity verdict, scored against the null fails on a structural difference that this PR causes, not on noise:

UI PARITY DIFFERENCES ON STABLE ACTIONS -- these need explaining:
  select_all_copy  parity-result r100K rep0: msg0(user):821->834c, msg1(assistant):19069->19082c, msg2(user):821->834c, msg3(assistant):63053->63066c
  select_all_copy  parity-result r100K rep1: (same)

Each fully mounted message row serialises 13 characters longer on the head arm, in both repetitions. That matches the role="article" the PR adds to the message roots in thread.tsx. The visible-region and behavioural modes matched (23 pairs), so only the structural digest sees it.

If the new role is intended, say so in the description so the difference is accounted for; nothing else in the run differs.

…ore the first style read

Rendering role="article" on every message root changed the markup of a fully mounted
thread, which carries no role on main, and the UI parity check flagged it on select all.
The roots render as they do on main again. The window publishes the role and the ordinals
in an insertion effect instead: after React has inserted the rows and before the layout
effect's anchor reads compute their style, so each row is styled once. Same sweep: style
recalculation 1,731 ms against 2,533 ms on main, p95 frame gap 29.7 ms against 35.7 ms.
@wasimysaid wasimysaid changed the title Studio: render the message rows' article role instead of writing it after mount Studio: publish the thread rows' role before their first style read Nov 12, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: fb4a3fdd67

ℹ️ 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 Nov 13, 2026
[skip ci]
@unslothai unslothai deleted a comment from wasimysaid Nov 13, 2026
@unslothai unslothai deleted a comment from wasimysaid Nov 13, 2026
@unslothai unslothai deleted a comment from wasimysaid Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@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. What shall we delve into next?

Reviewed commit: 56c5e57879

ℹ️ 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/tests/progressive-mount-glue.test.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. Nice work!

Reviewed commit: e970f0de02

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 13, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 13, 2026
@danielhanchen
danielhanchen merged commit 78635fb into unslothai:main Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants