Skip to content

Measure wide-dep useEffect cost; no fix warranted (bd-wfhd0dg5) - #936

Merged
shikokuchuo merged 2 commits into
refactor/useeffect-phase3from
refactor/useeffect-phase4
Oct 27, 2026
Merged

shikokuchuo merged 2 commits into
refactor/useeffect-phase3from
refactor/useeffect-phase4

Conversation

@shikokuchuo

Copy link
Copy Markdown
Member

Stacked on #931. Phase 4 of claude-notes/plans/2026-10-24-hub-client-useeffect-refactor.md (bd-wfhd0dg5).

Measures before fixing, per the profiling playbook — and the data says no wide-dep fix is warranted:

  • Adds src/utils/perfCounters.ts (gated on QUARTO_PERF_STATS=1 / localStorage.quartoPerfStats=1 / ?perf=1, read once at startup; inert otherwise) and instruments the five fileContents-wide effects plus the intelligence refresh. Gauges stay in the tree, same pattern as the Rust perf.intern counters.
  • Reconcile effect (useAutomergeSync): O(n) with a small constant — 0.073 ms/keystroke at 20 KiB docs, 1.0 ms at 327 KiB (measured with the real hook against a real Automerge doc and the real WASM vfs_add_file; Monaco emulated as an upper bound). The on-main VFS write is redundant with the sync client but ≤ 0.3 ms even at 327 KiB — not worth the branch-transition-tracking risk to skip.
  • useProjectSearch: the wide-dep corpus rebuild is ≤ 30 µs at 400 files; the residual ~0.8 ms/keystroke is MiniSearch reindexing the one changed file — intrinsic to a live index, independent of dep shape.
  • Trivial-body effects (route-nav, replay-VFS restore, both preview schedulers, intelligence refresh): five of them cost 0.036 ms/keystroke including the React commit.
  • useSectionThumbnails was dead code (no caller; OutlinePanel imported only its ThumbnailMap type) — deleted, closing the debounce item. refreshIntelligence already debounces at 300 ms inside useIntelligence; no fold-in needed.

No user-visible behavior change, so no changelog entry (same call as Phases 2–3).

Tests: full npm run test:ci green (1736 unit, 229 integration, 434 WASM) and npm run build green; eslint on touched files at exact parity with the Phase 3 tip. Not verified in a real browser session — the only behavior change is the dead-code deletion; the counters are inert unless enabled.

Phase 4 of the useEffect audit (plan:
claude-notes/plans/2026-10-24-hub-client-useeffect-refactor.md).

Adds src/utils/perfCounters.ts — a QUARTO_PERF_STATS/localStorage/?perf=1
gated counter helper — and instruments the five fileContents-wide effects
plus the intelligence refresh. Throwaway Node drivers (tsx + jsdom, real
hooks, real Automerge doc, real WASM vfs_add_file) measured per-keystroke
cost at geometric scales:

- Reconcile effect: O(n) with small constant, <=0.27 ms at <=82 KiB docs;
  the redundant on-main vfs write is <=0.3 ms even at 327 KiB — not worth
  the branch-transition-tracking risk to skip.
- useProjectSearch: corpus rebuild <=30 us at 400 files; the residual
  ~0.8 ms is intrinsic MiniSearch reindexing of the one changed file.
- Trivial-body effects (route-nav, replay-VFS, preview schedulers,
  intelligence refresh): 0.036 ms/keystroke for five incl. React commit.

No dep is narrowed and no work is moved; the counters stay in the tree.
useSectionThumbnails was dead code (no caller; OutlinePanel imported only
its ThumbnailMap type) — deleted, closing the debounce item. The
refreshIntelligence effect is already debounced at 300 ms inside
useIntelligence; no fold-in needed.
@shikokuchuo
shikokuchuo added this pull request to stack #926 October 27, 2026 15:58
@posit-snyk-bot

posit-snyk-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@shikokuchuo
shikokuchuo merged commit 875e7fd into main Oct 27, 2026
15 checks passed
@shikokuchuo
shikokuchuo deleted the refactor/useeffect-phase4 branch October 27, 2026 17:33
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.

2 participants