Skip to content

perf(web-ui): improve scrolling during concurrent BTW streaming - #3914

Merged
wsp1911 merged 1 commit into
openBitFun:mainfrom
wsp1911:webui-perf
Nov 14, 2026
Merged

wsp1911 merged 1 commit into
openBitFun:mainfrom
wsp1911:webui-perf

Conversation

@wsp1911

@wsp1911 wsp1911 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Improve scrolling when a long primary conversation and its /btw side conversation stream simultaneously. Replace broad relational CSS selectors with explicit startup state and a shared document focus subscription, and add a reproducible concurrent-scrolling E2E suite.

Type and Areas

Type: Performance improvement, regression coverage.

Areas: Web UI startup, shared design-system scrollbars, Desktop E2E, documentation.

Motivation / Impact

Streaming updates and virtualized row changes caused broad style recalculation through root-level startup :has() selectors and scrollbar selectors applied to every theme descendant. This reduced responsiveness even when scrolling the other conversation.

Optimization method

  • Drive startup visibility and logo handoff through data-startup-stage, clearing it on completion and fallback paths. Avoid keeping the application root as a relational-selector subject.
  • Replace universal scrollbar :has(:focus-visible) matching with one reference-counted focus subscription per document. Read native focus visibility after input/focus events and update the shared flag only when it changes; scroll events and streaming mutations do not update it.
  • Preserve hover and keyboard-focus behavior, scrollbar geometry, forced-color/touch rules, and startup animations. CSS-only consumers conservatively retain focused-viewport visibility.
  • Use CDP traces and selector/invalidation diagnostics to locate the bottleneck; measure acceptance runs separately without the profiler.

Measured benefit

The existing 200-turn, 100-tool-calls-per-turn template supplies 20,000 historical tool records. The test opens a real /btw child, drives two real Agent runtime sessions with a private loopback SSE model, seeds each response with 512 Markdown paragraphs, and releases 192 further paragraphs per pane at 90 ms intervals during each phase. The child is a new transient conversation, not a second persisted history fixture.

Both directions are measured in primary live content, primary historical tool content, and BTW live content. Each direction runs twice: 12 segments per version, 24 total. All functional checks pass.

Scroll region Baseline RAF FPS Optimized RAF FPS Improvement P95 frame interval (ms) Frames >33.33 ms
Primary live content 39.9 55.3 +38.8% 50.2 → 33.3 21.5% → 4.7%
Primary historical tools 18.4 40.7 +120.5% 133.4 → 50.1 64.4% → 21.6%
BTW live content 41.6 55.0 +32.3% 50.1 → 33.3 18.7% → 4.2%

FPS is time-weighted across pooled frame intervals; P95 uses the pooled nearest-rank distribution. Runs use the same native binary, protocol, harness, focused viewport, and immutable production frontend snapshots, with no concurrent build/test workload or CDP profiler. Environment: Windows x64, Core i7-8700, 32 GiB RAM, WebView2/Edge 157, 1992×1152 CSS-pixel viewport at 1.25 DPR; debug native host with production frontend assets.

These are RAF presentation opportunities, not compositor FPS. Historical tool calls are fixture records, not 20,000 newly executed tools. The historical tool region improves substantially but does not consistently reach 60 FPS.

Verification

Reproduce after building Desktop and production frontend assets:

cargo build -p openbitfun-desktop
pnpm run build:web
node tests/e2e/scripts/run-long-session-performance.mjs --suite btw-scroll --scenario multi-tool --repeats 2

The E2E checks both streams advance during scrolling, all wheel inputs reach the selected pane, further output preserves the reading anchor, both virtualized DOM windows remain bounded, return-to-latest reaches the final paragraph, and both completed responses render their completion markers. Raw frame timestamps, counters, screenshots, and frontend/native hashes are retained by the runner.

Current-head verification:

  • pnpm run check:web — passed (including appearance checks, typography audit, and TypeScript).
  • pnpm --dir src/web-ui exec vitest run src/app/styles/scrollbar.test.ts src/app/styles/scrollbarFocus.test.ts src/app/startup/startupOverlay.test.ts src/app/startup/startupPreload.test.ts src/app/startup/startupPerformanceContract.test.ts src/app/scenes/welcome/WelcomeScene.test.tsx src/infrastructure/design-system/OpenBitFunDesignSystemProvider.test.tsx — 104 tests passed.
  • node --test tests/e2e/scripts/long-session-performance.test.mjs design-system/packages/ui/tests/scroll-area.test.mjs — 12 tests passed.
  • git diff --check upstream/main...HEAD — passed.

Also passed during optimization: production build, standalone TypeScript check, pnpm run theme:color-audit:all (27 surfaces), pnpm run motion:audit, and a native-browser focus/scrollbar geometry diagnostic covering hover, mouse-focused buttons, keyboard focus, text inputs, and focused-node removal.

Reviewer Notes

  • AI-assisted implementation and validation. Coverage includes automated unit, contract, native-browser, and Desktop E2E checks; it is not a full platform matrix.
  • Performance numbers were collected before rebasing onto upstream's lint/check cleanup (05f2b55bb). The optimization patch has an identical stable Git patch ID after the rebase. Current-head checks above were rerun; performance measurements were not repeated after that rebase. A subsequent report-caption correction does not change workload or metric calculations.
  • Local Windows Desktop only. Remote workspace, remote control, Peer Device Mode, and Detached Dispatch were not exercised. There are no persistence or wire-protocol changes.
  • Previously, check:web stopped at the existing Dialog.module.css:77 typography violation. The upstream cleanup resolves that original blocker; current verification is reported above.
  • Benchmark evidence and diagnostic artifacts remain outside Git; the reproducible suite and documentation are included.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable.

Replace root-level startup relational selectors with explicit startup
state and share native focus-visible state across scrollbar consumers.
This preserves startup handoff and keyboard accessibility while avoiding
broad style recalculation as virtualized transcript content changes.

Add a BTW scrolling E2E suite using the 200-turn, 100-tool-call template.
Check concurrent streams, bidirectional scrolling, reading anchors,
bounded DOM windows, return-to-latest, and completed responses.

Across two repetitions per direction on local Windows Desktop, pooled
RAF FPS improves from 39.9 to 55.3 in primary live content, 18.4 to 40.7
in history, and 41.6 to 55.0 in BTW content. Both versions use the same
native binary and benchmark protocol without CDP instrumentation.

Validation: 24 E2E measurement segments, 104 focused tests, 8 benchmark
contract tests, 4 ScrollArea tests, native focus/geometry checks,
TypeScript, production build, and color/motion audits pass.
check:web remains blocked by the existing Dialog.module.css:77
typography violation. Remote scenarios were not exercised.
@wsp1911
wsp1911 merged commit ed456a2 into openBitFun:main Nov 14, 2026
13 checks passed
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