From c0985122b3f62e460c73ea6d67c426beb4dc9db2 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 26 Oct 2026 05:02:17 +0800 Subject: [PATCH] routing: the story's width is the one its observer last read (#3164) holdStory read steps.clientWidth on each of the story's ~10 draws a second, and each read laid the whole page out again first. The width now comes from the ResizeObserver already on steps, which runs after layout and so reads it for free; it fires on the first layout and on every change of width, which is all holdStory keys on. Run at 014680033 + this change, WebKit, the bin3164 sandbox app under load.sh (60 routes, ~800 keys), two folds open, 10s, two runs each: - holdStory 346 / 373 ms -> 170 / 200 ms (105-114 calls) - renderLog (includes it) 618 / 662 ms -> 430 / 503 ms GUI, each file alone, concurrency 2: routing-story-shrinks 10/10, routing-day-window 30/30, routing-bodies 10/10, routing-pin-leaves 22/22, routing-failed-open 8/8, routing-purpose-state 4/4. Broken by hand (the observer no longer sets the width): routing-story-shrinks 0/10. Stacked on 9787ca436, routing-story-shrinks and routing-model-rest together: one run had 1 red whose log wasn't kept, so it is unnamed; four runs after it, logs kept, 30/30 each. Not tried: the real app window. --- internal/gui/assets/plugins/routing/client.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index b33c22564..6c9407f5f 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -2324,10 +2324,13 @@ function routingPage(part) { // once, as it is then (the list coming in under it can take a // scrollbar's width off it before the first live request) const STORY_HELD = 3; - let storyHold = { key: "", told: new Map() }, storyDrawn = ""; + let storyHold = { key: "", told: new Map() }, storyDrawn = "", storyW = 0; function holdStory() { const follow = !pinned && !rp && !day; - const w = steps.clientWidth; + // the width as the observer below last found it: read here, it laid + // the whole page out again on each of the story's ten draws a second, + // half of what the story took with two folds open in WebKit (#3164) + const w = storyW; const key = JSON.stringify([follow, w, document.documentElement.lang]); if (key === storyHold.key && storyDrawn === headKey + stepsKey) return; if (key !== storyHold.key) storyHold = { key, told: new Map() }; @@ -2345,7 +2348,7 @@ function routingPage(part) { }); } // grown since it was measured (a font come in): measured again as it is - new ResizeObserver(() => { storyDrawn = ""; holdStory(); }).observe(steps); + new ResizeObserver(() => { storyW = steps.clientWidth; storyDrawn = ""; holdStory(); }).observe(steps); // renderCtx draws the request's context window under its story, with // its session's prompts request by request; drawn again only when what // it shows changes. Live, the next request is patched into the card