perf(hooks): resolve unmount error routing lazily (fixes #5217) - #5218
Open
JoviDeCroock wants to merge 1 commit into
Open
perf(hooks): resolve unmount error routing lazily (fixes #5217)#5218JoviDeCroock wants to merge 1 commit into
JoviDeCroock wants to merge 1 commit into
Conversation
📊 Tachometer Benchmark ResultsSummaryduration
usedJSHeapSize
Resultscreate10kduration
usedJSHeapSize
filter-listduration
usedJSHeapSize
hydrate1kduration
usedJSHeapSize
many-updatesduration
usedJSHeapSize
replace1kduration
usedJSHeapSize
run-warmup-0
run-warmup-1
run-warmup-2
run-warmup-3
run-warmup-4
run-final
text-updateduration
usedJSHeapSize
tododuration
usedJSHeapSize
update10th1kduration
usedJSHeapSize
|
|
Size Change: +28 B (+0.18%) Total Size: 15.8 kB 📦 View Changed
ℹ️ View Unchanged
|
The ancestor walk added in 46ddd2f ran for every unmounted component with hooks, even though its result is only consumed when a passive cleanup gets deferred to the after-paint flush. During a whole-tree unmount every ancestor's `_parentDom` is already nulled, so each walk scanned all the way to the root, making teardown O(hook components x depth) — a measurable regression for hook-heavy trees (#5217). Only resolve the surviving error-routing component when a passive cleanup actually needs deferring (`_passive && _cleanup`), at most once per component. Components that only use useState/useReducer, or whose effects have no cleanup, no longer pay for the walk at all; effects without cleanups also no longer schedule a pointless after-paint flush. Fixes #5217 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
JoviDeCroock
force-pushed
the
JoviDeCroock/issue-5217
branch
from
August 27, 2026 12:32
c84eacd to
8cb218f
Compare
JoviDeCroock
force-pushed
the
JoviDeCroock/issue-5217
branch
from
August 27, 2026 12:51
45e31b1 to
8cb218f
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.
Fixes #5217
The ancestor walk added in 46ddd2f ran for every unmounted component with hooks, but its result is only consumed when a passive cleanup gets deferred to the after-paint flush. During a whole-tree unmount every ancestor's
_parentDomis already nulled, so each walk scanned all the way to the root — making teardown O(hook components × depth). The ReactLynx repro (useState-only leaves) paid the full cost for a value it never used.This resolves the surviving error-routing component lazily: only when a state is both passive and has a cleanup to defer (
s._passive && s._cleanup), and at most once per component. Consequences:useState/useReducer-only components no longer run the walk at allunmountCleanups/ schedule an after-paint flush on teardown (deferring them was a no-op anyway — a pending effect of an unmounted component never runs, so no cleanup can appear later)Reproducing the issue's benchmark (5000 useState leaves, best of 7, fastest run) with a throwaway
test/browsercase:Size:
hooks/dist/hooks.mjs1423 → 1446 B brotli (+23 B).Existing coverage guards the semantics this touches: deferred-cleanup error routing ("should route deferred cleanup errors after a state update", "should route a deferred cleanup error past boundaries inside the removed subtree") and the #4299 deferral-ordering tests. Full suite green (1301 passed).
🤖 Generated with Claude Code