Repository navigation
perf(web-ui): eliminate WebKit layout/streaming bottlenecks and unify session loading - #3936
Merged
Merged
Conversation
…ng overhead
Eliminate major desktop WebView (especially macOS WKWebView) frame drops and
synchronous layout/style bottlenecks across session switching, turn navigation,
focus modality transitions, and long streaming conversations without altering
visual streaming cadence or session behavior:
1. Scoped scrollbar & reset CSS for WebKit/Blink:
- Gate legacy universal `*::-webkit-scrollbar*` rules behind
`@supports not (scrollbar-color: transparent transparent)` so modern
engines supporting CSS Scrollbars Level 1 skip matching 7 universal
pseudo-element rules on every descendant DOM node (~39% faster transcript
layout/remount in WKWebView).
- Rewrite fine-pointer scrollbar reveal rules via De Morgan equivalence so
toggling `:root[data-openbitfun-focus-visible]` only invalidates
`:focus-within` ancestors instead of `:root[...] *` across the whole DOM
(19.46 ms -> 1.71 ms per modality flip).
- Remove duplicate `AppLayout.scss` import in `AppLayout.tsx` and redundant
unlayered `!important` universal `*::before/*::after` box-sizing reset.
2. Eliminate sequential forced synchronous layouts in FlowChat & SceneBar:
- Run `centerFlowChatExtent` (`extent.style.left` write) after
`useFlowChatVirtualizer` layout reads, reuse `ResizeObserverEntry`
`borderBoxSize` in `publishOriginInset`, and set `tabIndex={-1}` in JSX.
- Skip `getBoundingClientRect()` DOM scans in `revealPendingTab` when the
SceneBar tab strip has no horizontal overflow.
- Split `measureRenderedItems` into an attribute-write pass followed by a
measurement-read pass, guard key-set diffing by `itemKeyRevision`, and
skip `getBoundingClientRect()` in `useTimelineInteraction` while following.
3. Incremental Markdown streaming & zero-allocation budget/hash walks:
- Strip closed inline code spans and ignore plain `<` comparisons in
`markdownSections` so technical replies (`Vec<T>`, `a < b`) keep 3k-char
section freezing instead of falling back to whole-document re-parsing.
- Run `rehype-raw` (`parse5`) only when `remark-rehype` emits `raw` HAST
nodes, strip code before math detection, enable `remarkCachedParse` for
settled math blocks, and reject skipped subtrees at the element level in
`useStreamingTextReveal`.
- Replace recursive `Object.entries` tuple allocations in
`estimateRetainedBytes` and `JSON.stringify` in `calculateTurnHash` with
zero-allocation traversals.
bobleer
force-pushed
the
bob/desktop-webview-perf
branch
from
November 16, 2026 05:37
4131f30 to
06150dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Targeted desktop WebView (especially macOS
WKWebView) and FlowChat performance optimizations — plus unified, calm session-switch loading presentation — addressing full-tree style invalidation, forced synchronous layout thrashing during session/tab/turn navigation, whole-document Markdown streaming fallbacks, memory-budget/persistence heap churn, and visually jarring full-pane session skeleton flashes.Scoped scrollbar & reset CSS (
@openbitfun/ui&AppLayout):*::-webkit-scrollbar*rules indesign-system/packages/ui/src/styles/scrollbars.cssbehind@supports not (scrollbar-color: transparent transparent)so modern engines supporting CSS Scrollbars Level 1 skip matching 7 universal pseudo-element rules on every descendant DOM node (-39% transcript remount/layout cost inWKWebView), with updated contract coverage inscroll-area.test.mjsandsrc/app/styles/scrollbar.test.ts.:root[data-openbitfun-focus-visible]only invalidates:focus-withinancestors instead of:root[...] *across the entire DOM (19.46 ms -> 1.71 ms, -91.2% per pointer/keyboard modality flip).AppLayout.scssimport inAppLayout.tsx(already imported globally insrc/app/styles/index.scss) and redundant unlayered!importantuniversal*::before, *::afterbox-sizing reset.Eliminate sequential forced synchronous layouts (
VirtualMessageList,useFlowChatVirtualizer,useSceneTabNavigation,useTimelineInteraction):centerFlowChatExtent(extent.style.leftwrite) afteruseFlowChatVirtualizerlayout reads sopublishOriginInsetdoes not trigger a second synchronous full-transcript layout pass; reuseResizeObserverEntryborderBoxSizeand movetabIndex={-1}to JSX.getBoundingClientRect()tab scans inrevealPendingTabwhen theSceneBartab strip has no horizontal overflow (scrollWidth <= clientWidthat origin), and memoizeopenTabIds.measureRenderedItemsinto an attribute-write pass followed by agetBoundingClientRectread pass, guard retired-keySetdiffing byitemKeyRevision, and skipgetBoundingClientRect()inuseTimelineInteractionwhile following live output.Incremental Markdown streaming & zero-allocation budget/hash walks:
<comparisons inmarkdownSectionsso technical responses containing generics (Vec<T>,Result<T, E>) or<comparisons retain 3,000-char section freezing instead of falling back to whole-document re-parsing on every streaming tick.rehype-raw(parse5) viarehypeRawIfNeededonly whenremark-rehypeemits at least onerawHAST node, strip fenced/inline code beforemayContainMarkdownMath, includeremarkCachedParsefor settled math blocks, and reject skipped subtrees at the element level inuseStreamingTextReveal.Object.entriestuple allocations inestimateRetainedBytes(5.37 ms -> 1.51 ms, -71.9%) andJSON.stringifyincalculateTurnHashwith zero-allocation traversals.Unify session-switch loading indicator with new-session / device-switch curtains (
HistorySessionLoadingBoundary):HistorySessionLoadingBoundarywith the centered muted<Spinner size="md" />(variant="logo", delayed by200msso fast<200msswitches show zero loading flash and go straight to settled content, while slower loads softly fade in tovar(--openbitfun-opacity-muted)), matchingDeviceSwitchCurtainand removing continuous full-pane mask-shimmer repaints.historySkeleton,historyOverlay,historyOpenIntent, and hiddenhistoryOpenIntentSpinnerAppearance slots, Visual Skin transparent chat artwork rules, anddata-history-loading-phasereadiness contracts; remove render-phasesetStateinHistorySessionLoadingBoundary.Type and Areas
Type: Performance optimization & UI polish
Areas:
design-system(@openbitfun/ui),src/web-ui(FlowChat virtualizer, loading boundary & timeline, SceneBar, Markdown pipeline, resource budget & persistence)Motivation / Impact
Desktop WebView profiling on macOS
WKWebView(80-turnmulti-toolfixture with 100 tool calls/turn + live loopback SSE streaming, identical native binary run sequentially in isolation) shows substantial latency and frame-drop reductions across interactive scenarios:multi-tool, 80 turns)data-openbitfun-focus-visible)streaming/session-switchstreaming/session-switch>33.3msstreaming/turn-jumpstreaming/turn-jump>33.3msstreaming/continuous-scroll-up>33.3msstreaming/continuous-scroll-down>33.3msstatic/first-openstatic/session-switch>33.3mslongRoundPerfHarness(300 rounds, 20 flushes)Verification
pnpm --dir design-system --filter @openbitfun/ui run test— 355/355 passed (includingscroll-area.test.mjsscrollbar CSS contracts)pnpm --dir design-system --filter @openbitfun/package-contract run test— 4/4 passedpnpm run check:web(typography audit, appearance contract audit,theme:color-audit:allacross 27 surfaces, theme visual governance contract, andtsc --noEmit) — passedpnpm run motion:audit— passedsrc/app/styles,HistorySessionLoadingBoundary.test.tsx,ModernFlowChatContainer.history-restore.test.tsx,VirtualMessageList.session-boundary.test.tsx,DeviceSwitchCurtain.test.tsx, headless Chromehistory-loading-paint.test.ts,AppearanceRegistry.test.ts,AppearanceCompiler.test.ts,resourceBudget.test.ts,PersistenceModule.test.ts,src/infrastructure/markdown,src/app/components/SceneBar,useTimelineInteraction.test.tsx,DesignSystemViteIntegration.test.ts,WorkspaceBody.presentation.test.ts,useFlowChatVirtualizer*.test.*,VirtualMessageList.session-switch.test.tsx,longRoundPerfHarness.test.tsx) — all passedpnpm run build:web&pnpm --dir src/mobile-web run type-check && pnpm run build:mobile-web— passedpnpm run check:repo-hygiene && node scripts/check-git-object-sizes.mjs --base upstream/main --head HEAD && git diff --check— passednode tests/e2e/scripts/run-long-session-performance.mjs --scenario multi-tool --turns 80 --repeats 4 --scroll-steps 40and--suite streaming-switch --scenario multi-tool --turns 80 --repeats 4) — 24/24 matrix samples and 4/4 streaming-switch samples valid.Reviewer Notes
WKWebView), and session-loading/appearance/persistence suites exercised simulatedpeer-devicesurface transitions and local headless Chrome Visual Skin paint fixtures; live Remote Workspace, Remote Control, Peer Device Mode, and Detached Dispatch hosts were not exercised end-to-end.Checklist