Skip to content

perf(threads): reuse streamed output and timeline rows - #524

Merged
nixuuu merged 2 commits into
devfrom
perf/streaming-timeline
Nov 11, 2026
Merged

nixuuu merged 2 commits into
devfrom
perf/streaming-timeline

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Streaming command output replaced a growing text node on every reveal, and the feed repeated key/group projection and map allocation across unchanged history. The snapshot reducer and ThreadState also scanned the entire item history for every delta. This change preserves completed output chunks and independent Markdown blocks, reuses timeline rows, contains layout at the existing scroll viewport, and indexes own items by id.

Draft: performance acceptance not achieved. On latest-dev baseline ae09805d2e8c7d218850d07e5d5ae44ccde238bc versus rebased head 85c3e4a811ae7ad385268ab0d057e894996da516, two final-series pairs qualified under the agreed host gates. Their after runs measured 34.51% / 34.18% main-thread busy, above the <25% target; dropped deadlines were 0.57% / 0.53% and p95 rAF 16.70 / 16.70 ms. Pair 3 was rejected for a 1796 KiB/s swap-in spike. There are only 2 of the required 3 qualified pairs. The maintainer designated this the last series in the window, so no further recordings or readiness command were run. CI is green. Earlier rejected attempts remain separately documented below and are not pooled into the result.

Changes

  • Render plain output in immutable groups of 32 complete lines; only the trailing group changes. Preserve every byte, whitespace, selection, horizontal scrolling and the existing height cap. Avoid splitting the full output when no tail view is requested.
  • Re-lex the last Markdown block while independent preceding blocks retain token identity. Use the full lexer for edits, option changes, CR normalization and reference syntax; late reference definitions refresh earlier inline tokens. Existing line-reveal timing, motion tokens and reduced-motion behavior remain intact.
  • Retain feed rows without allocating a full key map per delta. Reconcile by key when positions change; skip unchanged immutable rows when projecting virtual-feed keys/groups.
  • Replace the per-event item findIndex in the shared snapshot reducer and web ThreadState with id → position maps. Replacements reuse the map; appends add one position. Snapshots, history prepends and projected removals/reorders rebuild it. Inherited items never occupy an own-item key. The reducer transfers cache ownership to the next immutable array so reducing an older snapshot branch rebuilds independently; indexes are weakly held and are not serialized. Array copying and downstream feed projections remain linear.
  • Apply size/layout/style/paint containment to the already constrained, clipped scroll viewport. Keep ResizeObserver, follow-end and reader-intent handling.
  • Document the rules and measurement requirements in Polish. No sidebar or global-store changes in this PR; the branch now includes merged perf(navigation): update only changed sidebar rows #526 through dev. The shared reducer is also consumed by mobile. No mobile source, native configuration or dependency changes; its JS lookup receives the same optimization. No native runtime profiling or new fingerprint generation was performed in this static-only follow-up.

Trace findings and acceptance plan

Read the full #522 analysis and reused its fixture, measure.mjs and analyse.py. The exploratory traces still identify growing output layout and whole-document paint as costs; key/group projection and feed reconciliation also appear in CPU samples. All three exploratory timing runs encountered host contention and were discarded for acceptance. Their durations/load differ, so they are not a before/after performance claim.

The prepared runner performs before-1 → after-1 → before-2 → after-2 → before-3 → after-3, each 120 seconds. The current series is pinned to baseline ae09805d2e8c7d218850d07e5d5ae44ccde238bc (latest dev, including the GitHub stack and #529–#533) and rebased head 85c3e4a811ae7ad385268ab0d057e894996da516. Both halves retain all merged changes; the baseline patch reverses only this PR's streaming web changes and shared snapshot reducer. Earlier rejected sessions used older bases and heads; do not pool their results with this series. The runner retains the same #522 1,000-turn fixture, four running subagents, four expanded commands, seeded 500-thread sidebar plus six running rows, and 40 ms agent/tool tick. Chromium inherits taskset affinity to two complete physical cores (four logical CPUs); both versions use the same affinity. Affinity does not reserve cores against other processes, so a quiet window and host-log review are still required.

Each recording logs loadavg and vmstat before and continuously during the run, along with the measured interval timestamps and CPU affinity. A separate Svelte $effect counter pass follows the timing runs. The first session's counter incorrectly included mount/remount initial effects and was inconclusive. The corrected counter excludes the first effect per instance and passed in the latest session. Traces were analysed serially after the browser and private stack stopped. The application head is unchanged. The runner now checks preflight and each pair automatically, archives rejected attempts, and stops after three failed preflight probes or three contaminated attempts for a pair; it never marks a PR ready automatically.

The acceptance table below contains only qualified pairs P1 and P2, in that order. It is a partial two-pair result, not a completed three-pair acceptance. Pair 3 is excluded. Values separated by / are individual runs, not an aggregate.

Metric Before: P1 / P2 After: P1 / P2
Main-thread busy % 44.05 / 42.99 34.51 / 34.18 — target missed
Long tasks/min (>50 ms) 1.00 / 1.00 1.00 / 1.00
Dropped compositor deadlines % 1.56 / 1.51 0.57 / 0.53
p95 rAF frame gap, ms 16.70 / 16.70 16.70 / 16.70
Style, ms/s 36.11 / 35.68 34.45 / 34.48
Layout, ms/s 59.62 / 59.77 15.64 / 15.53
Paint, ms/s 48.41 / 48.02 38.82 / 38.62
Delivered ticks per ~120 s 2992 / 2992 2993 / 2994
Used heap P1: first → last; peak MB 164.0 → 202.7; 234.2 164.3 → 183.9; 207.2
Used heap P2: first → last; peak MB 164.5 → 222.4; 244.2 165.8 → 222.7; 222.7
Follow-end gap, px 0 / 0 0 / 0
Reader-anchor drift, px 0 / 0 0 / 0

Busy is the union of renderer RunTask intervals between trace marks. Dropped frames use compositor deadline markers; rAF does not measure presentation. p95 is reported at the harness's 0.1 ms precision. Memory is sampled used JS heap, not retained heap after GC. Both qualified pairs show less layout and busy time with the full streaming patch; this comparison does not isolate the item index from the output/feed changes. The busy target fails in both qualified after runs, irrespective of the missing third pair.

Final series and host qualification — 2026-11-11 UTC

The maintainer confirmed no other delegate was active. After the initial strict-zero-swap preflight and three earlier pair attempts were rejected, the host gates were explicitly revised before this final series:

  • reject swap-out ≥128 KiB/s in any sample, or cumulative swap-out ≥1024 KiB across both measured halves of a pair;
  • reject swap-in ≥1024 KiB/s, or ≥128 KiB/s for three consecutive seconds;
  • retain the CPU gates: loadavg ≥6, or ≥12 runnable with ≤15% idle;
  • preserve smaller swap reads/writes in the report. The host has about 6 GB of old swapped pages; small reads are not treated as CPU contention.

No prior rejected pair was reclassified. Samples are aligned to the logged measurement start/end timestamps, excluding vmstat's since-boot row. Totals below sum the 1-second rate samples and are approximate KiB transferred. Values are before / after within each pair.

Final pair Max loadavg Max runnable Min idle % Swap-in total KiB Swap-in max KiB/s Swap-out total KiB Swap-out max KiB/s Pair swap-out KiB Qualification
P1 1.64 / 1.60 7 / 6 75 / 82 184 / 848 24 / 436 0 / 0 0 / 0 0 Qualified
P2 1.85 / 1.90 8 / 8 72 / 77 112 / 124 16 / 32 0 / 0 0 / 0 0 Qualified
P3 1.90 / 1.65 6 / 8 76 / 75 48 / 1936 8 / 1796 0 / 0 0 / 0 0 Rejected

P3's after-3 sample at 01:41:22 UTC recorded swap-in 1796 KiB/s, 2 runnable and 84% idle, within its 01:40:48.287–01:42:48.601 interval. CPU stayed quiet, but the explicitly agreed swap-in threshold was exceeded, so both halves are excluded. P1's isolated 436 KiB/s read did not sustain the 128 KiB/s threshold for three seconds and therefore qualified. No final-series pair was retried.

P3 diagnostic results only — rejected:

Run Busy % Long/min Dropped % p95 ms Style ms/s Layout ms/s Paint ms/s Ticks Heap first → last / peak MB End gap / drift px
before-3 42.79 1.00 1.25 16.70 34.65 59.44 47.60 2992 160.0 → 180.3 / 228.6 0 / 0
after-3 35.43 1.00 0.60 16.70 34.46 15.67 38.65 2994 156.5 → 195.4 / 226.7 0 / 0

Next bottleneck from qualified after-2: renderer frame tasks occupy about 280.5 ms/s. Relevant native stages include Layerize 50.38 ms/s, Paint 38.62 ms/s (union, excluding nested double counting), visibility intersection processing about 38.6 ms/s, and style 34.48 ms/s. Layout is 15.53 ms/s; script-forced layout is only 31 events / 7.187 ms total over 120.010 s. Frame tasks include these stages, so the figures must not be summed with their parent. Paint remains rooted at #document with a viewport clip; that does not prove every pixel was repainted or identify the subtree that initiated invalidation. The next investigation is frame-wide paint/layer and visibility work, rather than another synchronous follow-end read optimization. The remaining long tasks include Svelte flushes reaching sidebar rows; no sidebar code was changed here.

Behavioral evidence: all six final recordings observed 0 px end gap and 0 px reader-anchor drift. The separate corrected Svelte probe passed over 200 ticks: zero updates to its 22 mounted completed-history row props, excluding first effects/remounts; each active command row updated 50 times, the active agent row 199 times and the live fold once. This verifies that probe's row-prop isolation, not every application effect.

Final artifacts: /var/tmp/canopy-perf-streaming/acceptance-20261111T012656Z/, including all six traces/reports, per-pair host-review.json snapshots, loadavg/vmstat logs, swap samples, frame-stage breakdown, metrics, anchors and row counters. The private stack stopped; the worktree is clean. No benchmark artifacts were committed.

Attempts immediately before the final series — rejected, never reclassified

acceptance-20261111T010231Z stopped before any recording: the original zero-swap gate rejected three preflight probes with mostly 4–16 KiB/s swap-in and 98–99% idle. The maintainer then permitted small swap-in while retaining rejection of any swap-out. Under that interim policy, acceptance-20261111T010651Z made three attempts at pair 1; all were rejected and remain excluded under their original policy:

Attempt Swap-in total KiB before / after Swap-in max KiB/s before / after Swap-out total KiB before / after Swap-out max KiB/s before / after Rejection
1 180 / 532 24 / 248 252 / 8 252 / 4 252 KiB/s at 01:07:27; after also had two 4 KiB/s writes
2 7228 / 120 696 / 24 0 / 12 0 / 12 12 KiB/s at 01:16:08, 90% idle
3 164 / 208 44 / 32 0 / 4 0 / 4 4 KiB/s at 01:21:38, 91% idle
Rejected attempt/run Busy % Long/min Dropped % p95 ms Style ms/s Layout ms/s Paint ms/s Ticks Heap first → last / peak MB
A1 before 44.11 1.00 1.24 16.70 34.90 58.54 47.36 2991 163.9 → 201.5 / 235.9
A1 after 34.93 1.00 0.78 16.70 35.88 15.81 39.96 2992 165.3 → 189.8 / 204.3
A2 before 42.98 1.00 1.00 16.70 34.15 58.52 47.13 2992 157.6 → 227.1 / 239.9
A2 after 36.17 1.00 0.69 16.80 35.56 15.76 39.40 2992 162.9 → 190.1 / 203.6
A3 before 42.77 1.00 0.90 16.70 34.75 58.19 47.52 2992 159.8 → 232.0 / 243.7
A3 after 37.39 1.00 0.62 16.70 37.38 17.03 42.56 2992 157.9 → 195.0 / 208.2

All six interim recordings had 0 px end gap/drift. Their raw evidence is in the three rejected-pair-1-attempt-* directories; these are not extra qualified pairs for the final series.

Validation

Latest-dev rebase: rebased without conflicts onto ae09805d2e8c7d218850d07e5d5ae44ccde238bc, keeping both sets of changes. bun install --frozen-lockfile, bun run typecheck, bun run lint, and bun run format:check passed on head 85c3e4a811ae7ad385268ab0d057e894996da516. The initial typecheck exposed a missing local graphql dependency from the merged GitHub stack; installing the existing lockfile resolved it. The branch was force-pushed with an explicit lease on its previous remote head. Fixture/counter/runtime patch applicability passed. No product-code changes were needed for the rebase.

Current remote CI on 85c3e4a811ae7ad385268ab0d057e894996da516: all checks passed, including static checks, all four test shards, web/Linux build, commitlint and the aggregate check. The previous head's shard-4 failure in linked-computer integration tests is historical; no CI rerun or unrelated code fix was made in this measurement session.

Index follow-up, rebased onto #526: bun run typecheck, bun run lint, and bun run format:check passed on head 767411e526eb15bdbf469a9138bbcd4d3454fd14. Rebase completed without conflicts and preserves both documentation sections. Added five pure reducer regressions covering a 7,000-item stream, inherited-id collisions, append/branch isolation, interleaved threads, replacement snapshots, projected reconnect removals and replayed/unknown events. These cases were typechecked but not run locally, per the latest instruction to perform static checks only. No build, browser, benchmark or test suite was run in this follow-up. Scratch runner syntax and fixture/counter/runtime patch applicability passed; the runner itself was not started.

Earlier validation, before this follow-up:

  • bun install, bun run typecheck, bun run lint, bun run format:check, bun run --filter @canopy/web build — passed.
  • bun test apps/web/test/streaming-render.test.ts apps/web/test/feed-prefix.test.ts apps/web/test/feed-rows.test.ts apps/web/test/work-fold-state.test.ts — 16 passed, 921 assertions. These are pure-data tests, including full-lexer equivalence at every streamed character boundary, not UI tests.
  • Exploratory Chromium checks: 0 px follow-end gap and 0 px reader-anchor drift. Short/long output, blank lines, tabs and Unicode had identical text, selection, height and scroll extents to the original single-text-node surface. Light/dark screenshots at 1512 px and 390 px were inspected. These establish observed behavior, not acceptance performance.
  • No UI/E2E suite, full integration/temp suite, native runtime profiling or fingerprint generation was run. Mobile code and native configuration are untouched. Svelte per-row update verification is inconclusive and the accepted paired table remains pending a future quiet-window run.

Copy audit (§8): no visible strings, labels, controls or terminology changed. Output is complete; existing truncation and accessible labels are retained. No traces, diagnostic scripts, screenshots or run artifacts are included in the commit.

Paint/Layerize follow-up from the saved #526 trace

Reused the existing analyser on p2-anim-after-trace.json from the parallel sidebar work; no browser or new recording was started. Over its 120.027 s interval, the trace records Paint 3,689.574 ms (30.74 ms/s), Layerize 6,640.412 ms (55.32 ms/s), PrePaint 3,662.294 ms and Commit 2,068.552 ms. Paint remains rooted at #document with the viewport clip. The four expanded output <pre> spans each account for approximately 284–289 ms across the whole recording, nested within root paint; they must not be added to it. Script-forced layouts total only 9.979 ms across 28 events.

This narrows the next investigation to document paint traversal/layer preparation and visibility processing after combining #524 and #526. It does not attribute the root cost to the streaming output subtree or establish an improvement for the new indexes. #526 already changes offscreen sidebar rendering on this same document. No additional CSS/layer promotion was introduced from these unpaired observations: the combined head still needs the controlled series, including anchor checks, before attributing residual costs or claiming any performance target.

Latest indexed-head attempts — REJECTED, not acceptance evidence

Session acceptance-20261110T223545Z, recorded 2026-11-10 UTC (23:36–23:51 CET). Baseline is merged #526 at 6b1531fe36d7250d29ed79d7d6dab4e4124a70d9; after is 767411e526eb15bdbf469a9138bbcd4d3454fd14. Same #522 fixture, 120-second trace windows, CPUs 4,5,10,11. Every row below is rejected. No accepted aggregate can be calculated.

Rejected run Busy % Long tasks/min Dropped deadlines % p95 rAF ms Style ms/s Layout ms/s Paint ms/s Ticks Used heap first → last / peak MB End gap / reader drift px
before-1 51.71 17.50 7.55 16.80 42.05 69.02 54.12 2933 159.8 → 165.6 / 228.7 0 / 0
after-1 37.41 1.00 0.96 16.70 38.16 16.40 41.89 2992 154.8 → 177.7 / 225.3 0 / 0
before-2 43.21 1.00 1.19 16.80 35.75 60.06 48.33 2992 162.3 → 185.5 / 220.4 0 / 0
after-2 36.26 2.00 1.06 16.70 36.73 16.47 41.28 2989 155.3 → 205.8 / 219.7 0 / 0
before-3 48.89 20.50 6.90 16.80 39.48 71.86 53.79 2920 161.1 → 200.4 / 240.9 0 / 0
after-3 37.02 1.00 0.86 16.70 36.62 16.08 40.49 2993 155.1 → 221.4 / 221.4 0 / 0

Reasons for rejecting whole pairs (UTC):

  1. Pair 1: before-1 at 22:36:27–30 had 22–26 runnable, 1% idle and swap-out up to 124,576 KiB/s; at 22:37:39–41 it had 19–29 runnable and 0–1% idle. These are inside 22:36:05.849–22:38:06.164.
  2. Pair 2: after-2 at 22:46:11 had 23 runnable, 1% idle and 736 KiB/s swap-out. The recording ended at 22:46:11.643, so the spike is inside the measured interval.
  3. Pair 3: before-3 at 22:48:04–06 had 26–27 runnable and 1% idle; at 22:48:29–33 it had 12–30 runnable, 0–12% idle and swap-in up to 3620 KiB/s. These are inside 22:46:58.759–22:48:59.057.

The gates were declared before inspecting results: reject for measured swap I/O, loadavg ≥ 6, or ≥12 runnable with ≤15% idle. Host samples were aligned to each measurement's timestamps; vmstat's initial since-boot average was excluded. All three pairs independently fail the CPU criterion, regardless of the smaller swap reads elsewhere. Low pre-run loadavg did not describe the full recording.

The retry acceptance-20261110T225704Z made no recordings: all three preflight probes at 22:57:13–22 failed for swap I/O. The last probe also reached 25 runnable/11% idle and 17 runnable/2% idle. The runner restored the worktree and stopped its private stack. The maintainer then explicitly stopped further attempts until no other agent is active.

Directional interpretation only: all three after runs show lower busy and layout time than their respective before runs. This is consistent with a cheaper streaming path, but contention was asymmetric and the patch toggles all of #524, not only the new indexes. Therefore it does not isolate the effect of id → position lookup or support a controlled speedup claim. The attribution helper also produced an invalid negative sampled total for the reducer in after-2; that estimate is discarded, not reported as a saving. A separate index-only comparison would be needed to quantify that component. The displayed busy figures remain above 25%; dropped deadlines straddle 1%. Rounded p95 is 16.70 ms in the after runs. None of these observations constitutes target acceptance.

Next bottleneck: native paint/layer preparation remains a substantial cost. In after-3, over 120.023 s, Paint is 4859.792 ms (40.49 ms/s), Layerize 6293.423 ms (52.43 ms/s), style 4394.809 ms (36.62 ms/s) and layout 1930.511 ms (16.08 ms/s). Paint remains rooted at #document; nested node timings do not identify the initiating subtree and must not be added to the root. Forced layouts total only 31 events / 6.278 ms, so synchronous follow-end reads are not the main recorded cost. Feed assembly and ThreadState's derived projections remain visible in samples; the index does not make the whole delta handler O(1).

Behavioral observations: all six recordings have 0 px follow-end gap and 0 px reader-anchor drift. The corrected 200-tick Svelte row probe passed: no updates to its 22 mounted completed-history row props after excluding initial effects/remounts. Active command rows each updated 50 times; the agent row updated 199 times and the live fold once. This checks row-prop update isolation in that probe, not every effect in the application or performance acceptance.

Artifacts remain outside the repo under /var/tmp/canopy-perf-streaming/acceptance-20261110T223545Z/ and /var/tmp/canopy-perf-streaming/acceptance-20261110T225704Z/, including raw traces, reports, attribution output, host-review.json, rejections.md, host logs and counter results. No product code or commits changed; no test suite or build was run in this recording session. PR stays draft; the acceptance table above stays pending.

Earlier attempts on the pre-index head — REJECTED, not acceptance evidence

All rows below are unaccepted measurements. Do not average them into an acceptance result or interpret the before/after differences as a controlled performance improvement. Both halves of a pair are excluded when either half is contaminated. Affinity was identical for every run: CPUs 4,5,10,11 (two complete physical cores). Each measured interval was approximately 120 seconds; the requested tick rate was 25/s.

Rejected run Busy % Long tasks/min Dropped deadlines % p95 rAF ms Style ms/s Layout ms/s Paint ms/s Delivered ticks Sampled used heap: first → last / peak MB End gap / reader drift px
before-1 69.61 3.00 9.32 16.80 55.68 97.26 166.37 2985 160.1 → 186.9 / 218.4 0 / 0
after-1 59.53 8.50 9.59 16.80 53.81 23.45 164.99 2962 161.0 → 188.0 / 238.6 0 / 0
before-2 61.03 5.00 8.22 16.80 45.25 88.75 150.19 2972 163.6 → 233.1 / 233.1 0 / 0
after-2 50.31 3.00 4.24 16.80 42.50 19.36 141.30 2991 160.6 → 172.3 / 205.7 0 / 0
before-3 66.58 3.00 10.01 16.80 51.93 95.06 162.09 2977 155.3 → 204.3 / 217.8 0 / 0
after-3 52.60 3.00 4.71 16.80 49.89 20.54 150.26 2996 163.7 → 226.8 / 226.8 0 / 0

Rejection evidence (UTC; vmstat logs use CET, UTC+1):

  1. Pair 1: after-1 overlapped 12–21 runnable processes and only 8–11% idle CPU at 18:32:41–18:32:43; swap-in reached 1152 KiB/s. Its recording interval was 18:31:30–18:33:30.
  2. Pair 2: before-2 hit 25 runnable processes and 1% idle CPU at 18:35:44, despite 96–98% idle before starting. after-2 independently hit 27 runnable processes and 1% idle at 18:38:44. Both spikes fall inside the respective 18:34:15–18:36:16 and 18:36:59–18:38:59 intervals.
  3. Pair 3: after-3 recorded 30,972 and 68,284 KiB/s swap-out at 18:43:11 and 18:43:12, inside its 18:42:28–18:44:29 interval. The substantial shared-memory pressure invalidates the pair even though CPU was not saturated then.

The maintainer explicitly stopped further attempts while the other agents remain active. None of these pairs was retried in this session. The next invocation must repeat all three pairs; the old traces and rejection log remain preserved.

Trace findings, diagnostic only:

  • In the three after traces, paint costs 141.30–164.99 ms/s, Layerize 73.56–89.20 ms/s, style 42.50–53.81 ms/s, and layout 19.36–23.45 ms/s. The largest paint spans are rooted at #document with the viewport clip. This identifies paint traversal and layer preparation as the next bottleneck to isolate; the trace does not establish which subtree initiated every invalidation, nor prove that every viewport pixel was repainted.
  • For example, after-3 records 18,033.54 ms Paint, 9,643.04 ms Layerize, 5,987.21 ms style, and 2,465.22 ms layout over 120.02 seconds. Per-node paint spans nest inside root spans and must not be added together. Script-forced layout is only 35 events / 11.97 ms total in this trace, so follow-end's synchronous reads are not the dominant recorded cost.
  • Script samples still include feed assembly and ThreadState/snapshot traversal: after-3 has approximately 760.5 ms self samples in FeedBuilder.build, 745.9 ms in a ThreadState callback, and 640.5 ms in the snapshot reducer callback. These are sampled estimates, not additive inclusive timings. They are smaller than the native paint/layer stages and do not establish an O(1) delta path.
  • All six runs observed 0 px follow-end gap and 0 px reader-anchor drift. The separate 200-tick counter probe saw 200 active-agent row effects and 50 effects for each command. Three completed-history keys each had one effect; initial mounts/remounts were not distinguished by the original probe, so unchanged-row update isolation remains unverified.

The observed after numbers are above the requested thresholds, but host contamination prevents an accepted pass/fail performance conclusion. The PR remains draft. No readiness command was run.

Artifacts stay outside the repository in /var/tmp/canopy-perf-streaming/acceptance-20261110T182822Z/: six traces/reports, per-run metrics/anchor/inventory/layers, timestamped host logs, rejections.md, row-counters.json, and comparison.md. The ready-to-invoke scratch runner remains bash /var/tmp/canopy-perf-streaming/run-pairs.sh; it checks the expected head, restores temporary patches, and never marks the PR ready automatically. No diagnostic artifacts were committed.

Related: #522

Related: #526

@nixuuu
nixuuu force-pushed the perf/streaming-timeline branch from 99ce505 to 767411e Compare November 10, 2026 19:42
Retain line-aligned output chunks and independent Markdown blocks, reuse feed metadata, and isolate the scroll viewport layout. Paired acceptance recordings remain pending a quiet host window.

Related: #522
Maintain own-item positions through streamed replacements and appends. Rebuild after history changes and keep snapshot branches isolated.

Related: #522

Related: #526
@nixuuu
nixuuu force-pushed the perf/streaming-timeline branch from 767411e to 85c3e4a Compare November 11, 2026 01:02
@nixuuu
nixuuu marked this pull request as ready for review November 11, 2026 01:51
@nixuuu
nixuuu merged commit e318104 into dev Nov 11, 2026
11 checks passed
@nixuuu
nixuuu deleted the perf/streaming-timeline branch November 11, 2026 01:52
nixuuu added a commit that referenced this pull request Nov 12, 2026
Animate timeline work and nested command disclosures on the UI thread. Replace delayed inverted-list anchor corrections with a bounded header session, isolate disclosure state, and keep web manual headers anchored consistently.

Verification is pending the maintainer test window; publish as a draft so CI runs remotely before local checks or profiling.

Related: #524
Related: #545
nixuuu added a commit that referenced this pull request Nov 12, 2026
Expanding or collapsing turn work currently changes its height at once,
and the inverted mobile timeline corrects the tapped header only after
two frames and again after 180 ms. Native cell anchoring can also move
the viewport during that interval. Nested tool-group state lives in the
turn, rebuilding its work rows on every toggle.

This change keeps the manual disclosure header as the scroll anchor,
including the latest turn, and adds a shared mobile accordion for turn
work and nested command groups. Rebased onto `dev` after #545
(`1c65b93173a8c820618bd9afd45fe3ab1ba95246`) without conflicts.
Native-device checks remain with the maintainer; the measured evidence
and its limits are below.

### Changes

- Replace delayed JS header measurements with an active UI-thread
Reanimated `measure` / `scrollTo` session. Pause
`maintainVisibleContentPosition` during manual disclosure motion; cancel
on a reader drag, superseding tap, or unmount, then restore automatic
anchoring. Invalid measurements do not issue a scroll correction.
Preserve the existing inverted FlatList and stable turn keys; do not
introduce item-height estimates or list layout animations.
- Add `TimelineDisclosure`: lazy first mount, retained body through
collapse and reversals, one initial layout measurement, synchronous UI
measurements on subsequent toggles, and natural height after opening.
Height and the existing stable chevron use the shared `fast` /
`smoothOut` motion. Reduced motion changes both immediately. Hidden
retained bodies stop viewport clocks/decorations and are excluded from
touch and accessibility traversal.
- Keep nested-group state inside each group. Memoize body rows and turn
cells, retain the turn data array across list-wrapper updates, and keep
timeline directory/quote callbacks stable. Suppress image-viewport
refresh work during manual corrections. No custom JS animation-frame
loop is used.
- Web already anchors historical headers through `VirtualFeed.keep`;
remove the latest-fold exception so it follows the same rule. Apply that
contract to the long-thread fixture. Update the Polish timeline, mobile,
and performance documentation. No mobile thread-list rows, dependencies,
native configuration, or UI text changed.

### Verification

- Static inspection confirms the previous body was conditionally mounted
without a height transition, and the anchor combined two delayed JS
measurement passes with native visible-cell anchoring. This is a
diagnosis of the competing correction path; the exact one-frame flicker
still needs native reproduction and confirmation. #524 changed web
streaming/shared snapshot reduction, not the mobile disclosure/anchor
implementation, so it is context only.
- Local `bun install` and `bun run gen:check` passed. Focused
gateway/mobile/history checks passed: `bun test
tests/integration/ui-thread-deltas.test.ts
tests/integration/mobile-devices.test.ts
tests/integration/history-pages.test.ts` — 24 tests, 154 assertions,
zero failures. Did not repeat the full `check:tmp`, as requested.
File-scoped oxfmt and oxlint previously passed with zero diagnostics. No
web UI tests were added.
- Rebased-head
[CI](https://github.com/itsoltech/canopy/actions/runs/43215766418)
passed generated-code checks, all typechecks (including mobile and
Svelte), lint, formatting, all four test shards with temp-directory
checks, and the web/Linux builds. The Angular PR title also passes
remote commitlint.
- Production fingerprints match the rebased baseline exactly on both
platforms, using `bunx [email protected] fingerprint:generate --platform
<ios|android> --build-profile production --json --non-interactive`: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. Baseline dependencies were
installed separately to preserve relative source paths. No native
library, configuration, or dependency changes.
- Real Chromium check of `/dev/long-thread?turns=1000&inherited=0`, with
production `FeedRowView` / `VirtualFeed`: historical and latest
summaries expand/collapse with **0 CSS px maximum sampled header
drift**. Historical summaries: six toggles per combination at 1280×800
and 390×844, light and dark. Latest summary: six toggles per theme at
desktop width, plus ten toggles per theme starting at the bottom
(initial bottom gap 0). Sampled the header on every animation frame for
550 ms per toggle; inspected both themes and widths visually. The
ordinary thread page calls the same `keep(rowKey)` API; the browser
scenario used synthetic long-thread data, not a user's live thread.
- Copy audit: no UI strings changed. No QA logs, screenshots,
recordings, counter instrumentation, or benchmark artifacts are
committed. Physical scroll limits still apply when collapse leaves less
content than the viewport. Retaining previously opened bodies trades
local state continuity for memory within the virtualized turn window;
measure that on long threads.

### Render counts

Temporary render counters executed the real mobile `ThreadTimeline`,
`TimelineTurn`, grouping, memo boundaries, disclosure state and anchor
session with React 19.3.0's renderer on Bun 1.4.4. Dataset: 1,000
synthetic turns; a fixed 20-turn mounted window; ten summary toggles and
ten nested-group toggles after initial mount. Native geometry, frame
scheduling, list windowing and leaf presentation were stubbed. These are
measured JavaScript reconciliation counts, **not native-device frame
pacing or native FlatList measurements**.

| Operation | Before: rendered turn cells | After: rendered turn cells |
| --- | ---: | ---: |
| Summary expand/collapse | 1 | 1 |
| Nested command group expand/collapse | 1 | 0 |
| Parent update with identical timeline inputs | 20 | 0 |

No other turn rendered during isolated toggles, and no turn remounted in
either version. Newly mounted body rows were counted separately: first
summary open 2 before / 2 after; first nested-group open 1 / 1. Summary
close/reopen rendered zero body rows after the change; before, closing
rendered the answer and reopening remounted the two work rows. Native
UI-thread motion/anchoring, long-thread native scrolling, and
retained-body memory still require the device checks below.

### Maintainer device checks

1. On the same long thread on iPhone and Android, put a completed
summary near the middle of the screen, with earlier messages visible
above it. Open and close it ten times, then rapidly reverse it before
the 250 ms motion ends. Record at 60 fps: the header and content above
it should remain fixed, the body and content below should move
continuously, and no frame should show unrelated earlier messages.
2. Repeat for the latest turn while at the bottom and for nested “Ran N
commands” groups. Expand command details inside a group, close/reopen
the parent, and check retained state, smoothly turning chevrons, fully
hidden closed bodies, and no clipped content after settling. Repeat with
a long label and a tall result.
3. Repeat with the keyboard open and closed, then drag the timeline
during the animation. The drag should immediately take over; the
composer should not fold from a programmatic correction. Load an older
history page and use “Jump to latest” afterward to check automatic
anchoring and following.
4. Enable system Reduce Motion, then repeat the toggles in light/dark
and phone/wide layouts. Height and chevrons should switch immediately
without a viewport flash. VoiceOver/TalkBack should report expanded
state and skip controls inside collapsed content.
5. Confirm the reconciliation counts on a native device with React
Native Profiler/render counters, excluding initial mounts and counting
newly mounted children separately. Compare scrolling the same 1,000-turn
thread and memory after opening many summaries. On web, optionally
repeat the synthetic-fixture checks in a real conversation, including
nested groups.

Related: #524
Related: #545
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