Skip to content

perf: reduce repeated and serialized UI/flow-chat work - #3962

Open
Raing5Days wants to merge 5 commits into
openBitFun:mainfrom
Raing5Days:perf/session-switch-speed
Open

Raing5Days wants to merge 5 commits into
openBitFun:mainfrom
Raing5Days:perf/session-switch-speed

Conversation

@Raing5Days

@Raing5Days Raing5Days commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

This branch reduces repeated or serialized work in several flow-chat and UI paths:

  • trajectoryRange.ts previously built a JSON key for every node twice when resolving two endpoints, and walked the selected range five times to build one summary. Both paths now use single passes, with a fallback that preserves the old comparison for unfamiliar endpoint shapes.
  • fileTreeReveal.ts rebuilt regular expressions and intermediate arrays on each reveal. Reusable patterns are hoisted, and path expansion uses one loop while preserving Windows, POSIX, UNC and remote-path semantics.
  • modelImageBudget.ts scanned the entire model list even when no selectable primary/pool route existed. It now returns immediately in that case and otherwise uses a Set plus one pass to find the narrowest native-image ceiling.
  • globalSearchActivator.ts opened a session hit by first awaiting the workspace switch and only then loading the search hit's persisted session metadata. These two operations are independent (the metadata read addresses the target workspace directly), so they now start together. This removes one host round trip from search-all-to-session navigation, most visible when the target is in another workspace.

Evidence

Local OpCase microbenchmarks (jsdom module cost, not frame time):

  • trajectory range: 85.83 to 7.30 us/call against a 60.08 us/call budget.
  • file tree reveal: 0.349 us/call against a 2.9272 us/call budget; focused tests pass.
  • model image budget: 0.219 us/call against a 0.5509 us/call budget; focused tests pass.

Global-search session navigation: a deterministic regression test (globalSearchActivator.test.ts) holds the workspace switch pending and asserts the metadata read has already started, so the old serialized order fails and the new overlapped order passes. This is a control-flow guarantee, not a frame-time claim; the saved time is one host round trip on cross-workspace session opens.

Testing

  • node scripts/run-vitest.mjs run src/app/global-search - passed, 93 tests.
  • node scripts/run-vitest.mjs run src/tools/file-system/utils/fileTreeReveal.test.ts src/flow_chat/utils/modelImageBudget.test.ts - passed, 9 tests.
  • Local-only equivalence test for fileTreeReveal against the previous implementation over 13 path cases - passed (not committed).
  • pnpm run lint:web - passed.
  • pnpm run type-check:web - passed.
  • pnpm run check:repo-hygiene - passed.
  • node scripts/check-git-object-sizes.mjs --base origin/main --head HEAD - passed.
  • pnpm run check:web stops at Stale MiniApp chrome theme: src/shared/miniapp-chrome/generated/theme.css before type-check runs. This failure is present on the clean base tree and is unrelated to these files; type-check was run separately and passes.

Remote scenarios: none exercised. These changes touch no IPC, persistence, protocol, remote-surface behavior, or permission path.

AI-assisted: yes, written with an agent. Testing level: fully tested at module level (focused unit tests, benchmark budgets, and equivalence/control-flow tests where applicable); lightly tested at component level.

Generated with OpenBitFun

…y node key

The trajectory panel is keyed by session, so switching sessions remounts it and
its mount pass runs over the whole loaded node page: the saved endpoint keys were
resolved with one built JSON key per node per endpoint, and the range summary
walked the selection five times through filter passes and a reduce closure.

- resolveTrajectoryRange reads the two endpoint identities once and matches node
  fields in a single pass. An endpoint from an unexpected source still falls back
  to the former per-node key comparison.
- summarizeTrajectoryRange counts kinds, tallies errors and sums both durations in
  one pass, keeping "no duration recorded" distinct from a measured zero.

Measured with the local OpCase benchmark (400 nodes, panel mount pass, 72000
measured calls): 85.83 us/call -> 7.30 us/call against a 60.08 us/call budget.
The number is module cost, not a frame time.

Testing: node scripts/run-vitest.mjs run src/flow_chat/trajectory (49 passed);
pnpm run check:web (pre-existing failures only: stale MiniApp chrome theme
artifact and appearance-contract warnings).
…tation

trajectoryRange.ts now resolves endpoints by comparing node fields and
summarizes a range in one pass. Both replacements are checked against the
previous slice/filter/key-scan implementations copied into the test file, so a
difference in counts, duration sums, empty selections, endpoint identity, or
first-match behaviour fails here instead of in the panel.

Covered on purpose:
- every interesting bound shape: reversed, equal, negative, past the end;
- an empty selection, where the previous code reported no endpoints;
- "no duration recorded" vs a measured zero;
- identities that need JSON escaping (quotes, backslashes, newlines, NUL,
  non-ASCII), so the parsed endpoint path cannot drift from the key format;
- a prepended page, a repeated identity, a malformed or missing endpoint.
Hoist reusable regular expressions and replace per-item `.map/.filter` work with a single loop while preserving path normalization and casing semantics.
Return early when no selectable route exists and use a Set plus one pass to compute the narrowest native-image ceiling, preserving the previous model selection semantics.
@Raing5Days Raing5Days changed the title perf(flow-chat): resolve trajectory range endpoints without rebuilding every node key perf(flow-chat): reduce repeated UI helper work Nov 17, 2026
Starting the workspace activation and the search-hit metadata read together removes one host round trip from the critical path of opening a session found through global search, which is most noticeable when the target lives in another workspace.
@Raing5Days Raing5Days changed the title perf(flow-chat): reduce repeated UI helper work perf: reduce repeated and serialized UI/flow-chat work Nov 17, 2026
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