Skip to content

fix: harden runtime hooks and speed up early React useFiber - #111

Merged
aidenybai merged 3 commits into
mainfrom
fix/runtime-resilience
Sep 6, 2026
Merged

fix: harden runtime hooks and speed up early React useFiber#111
aidenybai merged 3 commits into
mainfrom
fix/runtime-resilience

Conversation

@aidenybai

@aidenybai aidenybai commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Summary

Follow up on the runtime robustness audit and the request to check useFiber performance. Root README and unrelated kitchen-sink work are unchanged.

useFiber performance

  • Ordinary React 16.8–16.12 updates previously searched the work-in-progress root for every capture. Across many components this could become quadratic.
  • Reuse React-derived alternate/parent reflection, with reducer-marker and rendering-root checks. Retain the existing root search for ambiguous topology; no ref-parity guessing.
  • Reuse the retained capture record instead of allocating a replacement on every update.
  • Add operation-count regressions proving zero unrelated-subtree reads, alongside exact rendering-Fiber identity, across nine React fixtures × development/production/profiling.
  • Add pnpm --filter conformance bench:use-fiber: actual production ESM, isolated React versions, with/without-hook baselines, 100/1,000 components, and 32-preceding-hook cases. Timing is diagnostic, not a flaky CI threshold.

One local Node 24.20.0 / Happy DOM run, 1,000 null-rendering components, no preceding hooks, median of five samples:

React Before, ms/update After, ms/update After, without useFiber
16.8.6 2.719 0.262 0.130
18 0.239 0.210 0.116
19 0.237 0.195 0.142

The meaningful improvement is the early-React root-search reduction. Modern-React timing differences are small and are not claimed as a guaranteed speedup. These synthetic results are not browser/mobile guarantees.

Runtime robustness

  • Isolate synchronous activation, renderer-injection, hook-replacement, and instrumentation listener exceptions. Existing commit/schedule/post-commit/unmount callbacks preserve their receiver and get the same isolation. Root bookkeeping and Fiber-ID cleanup still run.
  • Separate explicit work-tag associations from inherited caches. Generation-based invalidation fixes late associations and changed renderers while preserving explicit subtree/root associations and detached metadata. Unchanged associations retain the cached fast path.
  • Replace recursive rendered-phase visitors with iterative walks. Tests cover 20,000-deep and 20,000-wide mounts, updates, and simulated unmounts, preserving existing visitation order.
  • Handle React 16's unwrapped Suspense primary children. Live version/build tests verify all visible primary/fallback siblings on mounts and updates.

Intentional error-contract change: synchronous listener exceptions now go to console.error instead of escaping and stopping dispatch. Reporting failures are contained too. React's injection error handling otherwise prevents it from retaining the hook for future commits. Rejected promises and a foreign hook's own failing inject implementation are not isolated.

Remaining boundaries

  • Initial production/profiling capture with already-locked bind remains unsupported. Updates after successful capture still avoid bind assignments and passive effects.
  • Hook-marker scans remain linear in hook count; ambiguous early-React topology can still use the full-tree fallback. useFiber is not universally constant-time.
  • Changed renderer associations can require unrelated inherited work-tag caches to revalidate once. Ordinary unchanged associations do not.
  • No universal React parity, full SES-lockdown support, or browser/Detox validation is claimed.

Validation

  • Reproduced three cache failures, three listener-dispatch failures, five rendered-traversal failures, and six early-React unrelated-subtree scans before their fixes.
  • pnpm test:conformance: 1,835 passed, two existing skips, plus typechecks, production build, and all four development/production × ESM/CJS packaged checks. The built use no memo guard passes.
  • Verified all 1,835 tests and typechecks with packages/bippy/dist removed. The shared Fiber fixture now uses an explicit source import, so it also works in the isolated unit project without a build or a bare-package alias.
  • pnpm check: no errors, two existing E2E warnings.
  • Upstream verification: eight source hashes and 12 direct ports at f1f7ed2ac267a21dd2e3e67c4a606b9cf56e360b.
  • Unit coverage: statements 92.66%, branches 88.62%, functions 91.53%, lines 94.42%.

Source review used the local facebook/react checkout: ReactFiberDevToolsHook.js, ReactFiberTreeReflection.js, hook cloning/reducer internals, and the React 18.3.1 DevTools Suspense traversal with its pre-Offscreen compatibility path. Audit findings, contracts, benchmark methodology, and remaining limitations live in packages/conformance/README.md.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4fc0a70

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 3:03pm 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@111

commit: bd8a2c4

@aidenybai
aidenybai merged commit 0ac832d into main Sep 6, 2026
11 of 12 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