Skip to content

perf: speed up hook inspection and source lookups - #113

Merged
aidenybai merged 4 commits into
perf/benchmark-public-apifrom
perf/source-hot-paths
Sep 6, 2026
Merged

perf: speed up hook inspection and source lookups#113
aidenybai merged 4 commits into
perf/benchmark-public-apifrom
perf/source-hot-paths

Conversation

@aidenybai

@aidenybai aidenybai commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Stack

Depends on #112 (base: perf/benchmark-public-api), which is stacked on #111.

Changes

  • Parse trailing stack locations from the end instead of repeatedly matching the full location with a lazy regex; preserve line-terminator behavior.
  • Parse stack lines directly rather than splitting/filtering each already-split line.
  • Reuse parsed frames inside each hook-inspection tree build, skipping repeated parsing/classification of shared frames. No hook-value/result caching; no persistent inspection cache; public parseStack results remain fresh.
  • Use indexed reverse source-map scans and skip materializing later ignored matches once a valid fallback exists. Keep mutable-map behavior, first-duplicate semantics, and application-source preference.
  • Add distinct hook-call-site and ignored-mapping benchmarks to avoid optimizing only repeated-loop fixtures.
  • Replace executable benchmark strings with typed workers and an explicit 128-site TypeScript hook fixture. Compile the cold-import probe before starting native Node.
  • Validate report structure and exact timing summaries, source-content identity, hook values, and distinct call-site locations.
  • Give live fixtures independent setup/cleanup; share registration, variants, groups, statistics, process execution, and report formatting.
  • Journal completed groups incrementally. Interrupted runs retain their results without replacing the last successful report.
  • Simplify the root README's getSource description as requested.

No public export changes or changes to useFiber capture. Unrelated kitchen-sink work remains excluded.

Paired performance results

Historical production bundles before (35fe6a6) versus after, using identical expanded fixtures on local Node 24.20.0 / Apple M5 Max. The later typed-worker refactor changes fixture stack layout; these measurements are not comparisons across that refactor. Timings are diagnostic, not browser/mobile guarantees.

Workload ESM before → after CJS before → after
Inspect 128 state hooks 3.21 → 2.28 ms 3.74 → 2.83 ms
Inspect 128 custom-hook calls / 384 primitives 9.70 → 6.92 ms 11.39 → 8.50 ms
Inspect 128 distinct state-call sites 3.82 → 3.03 ms 4.36 → 3.56 ms
Parse 1,000 V8 frames 655 → 464 µs 633 → 470 µs
Source-content lookup / 10,000 filenames 183 → 40 µs 181 → 40 µs
Function-name lookup past 10,000 ignored mappings 121 → 59 µs 125 → 63 µs

Native Error capture and Node's source-map-aware stack formatting remain substantial costs. Inspection still replays user code; reverse lookups and deep ancestor walks remain linear. Machine-load variation was visible in other runs, so these are not timing thresholds.

Correctness and validation

  • New differential test: 17,027 location comparisons against the previous parser, including ports, route groups, malformed prefixes, and Unicode line separators.
  • Verify per-parser reuse/isolation, fresh public frames, live changes to source names/contents/mappings/ignore sets, and first duplicate behavior.
  • Reproduced the ignored-candidate regression against the old implementation: 1,001 name reads instead of three; the optimized implementation passes.
  • pnpm test:conformance: 1,857 passed, two existing skips; typechecks, production build, and four packaged modes passed. An earlier full run hit an existing React 16.0 subprocess test timeout under load; the complete rerun passed without changing its timeout.
  • pnpm check: zero errors, two existing E2E warnings.
  • Upstream verification: eight source hashes and 12 direct ports.
  • Current expanded built smoke matrix passed, covering all 65 callable exports. All 72 typed useFiber worker configurations passed across nine React fixtures and both formats. Added a regression for flushing the report and terminating despite early React scheduler MessagePorts.
  • Paired source/inspection benchmarks passed before the benchmark-quality refactor.
  • Completed the full benchmark again at 3a89258: 792 verified result rows, covering all 65 callable exports, with the typed workers, all 128 distinct call sites, and incremental journaling. Exit status 0; results saved under benchmarks/results/run-9kgLiO/ and latest.*.
  • Unit coverage rerun after the benchmark-quality refactor passed (947 tests, two existing skips): 92.87% statements, 88.90% branches, 91.60% functions, 94.53% lines. The updated stack parser has 100% statement/line/function coverage and 98.73% branch coverage.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3a89258

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
bippy Ready Ready Preview Sep 6, 2026 12:54am UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/bippy@113

commit: 3a89258

@aidenybai

Copy link
Copy Markdown
Owner Author

Pushed benchmark-quality fixes in 16c82ff and 3a89258, plus the requested getSource README simplification in f1effd0. Full conformance: 1,857 passed / two existing skips; all four packaged modes passed. Full benchmark at 3a89258: 792 verified rows, all 65 callable exports, exit 0. Core CI, web E2E, Android E2E, and review passed. Retrying only the failed iOS job: Detox exited with proper-lockfile ECOMPROMISED (Unable to update lock within the stale threshold), before any test assertion failure. Unrelated kitchen-sink work remains uncommitted and excluded.

@aidenybai

Copy link
Copy Markdown
Owner Author

Validation complete: the iOS retry passed without code or assertion changes. All current PR checks are green, including web, Android, iOS, build, check, typecheck, test, and review. Local full benchmark: 792 verified rows / all 65 callable exports. Local conformance: 1,857 passed, two existing skips. Coverage rerun passed at 92.87% statements / 88.90% branches. All intended changes are pushed; unrelated kitchen-sink work remains excluded.

@aidenybai
aidenybai merged commit f52e048 into perf/benchmark-public-api Sep 6, 2026
16 of 17 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