perf(desktop): skip the timeline rect walk while following the bottom

ThreadTimeline's scroll compute read getBoundingClientRect for every user
message per scroll frame; interleaved with React's streaming style writes
each read forced a full reflow — the hottest self-time frame in the
multitab profile (620ms over one 5-tab run). While the viewport is pinned
to the bottom the active prompt is simply the last entry, so answer from
data and save the layout reads for actual scrollback.
This commit is contained in:
Brooklyn Nicholson 2026-07-26 00:20:49 -05:00
parent 47f0cdf3a2
commit 982a425162

View file

@ -196,6 +196,17 @@ export const ThreadTimeline: FC = () => {
const compute = () => {
raf = 0
// Pinned to the bottom (the entire streaming steady-state): the active
// prompt is simply the last one. Skipping the walk matters — it reads a
// rect per user message per scroll frame, and interleaved with React's
// streaming style writes each read forces a full reflow (the single
// hottest frame in the multitab profile).
if (viewport.dataset.following === 'true') {
setActiveIndex(prev => (prev === entries.length - 1 ? prev : entries.length - 1))
return
}
const top = viewport.getBoundingClientRect().top
const offsets = entries.map(entry => {