fix(@typegpu/react): Cleanup on-demand root on unmount#2554
Merged
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (355 entries).
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu. |
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.93, 1.78, 3.89, 6.08, 7.53, 10.25, 21.27, 23.32]
line [0.92, 1.96, 4.57, 7.02, 7.39, 11.23, 20.60, 21.62]
line [0.93, 1.89, 4.32, 7.06, 7.99, 9.09, 20.31, 24.99]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.31, 0.56, 0.72, 0.84, 1.13, 1.21, 1.49, 1.57]
line [0.35, 0.55, 0.72, 0.90, 1.18, 1.21, 1.42, 1.59]
line [0.28, 0.54, 0.65, 0.81, 1.11, 1.21, 1.43, 1.57]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.88, 2.06, 3.89, 6.19, 12.71, 24.85, 54.61, 110.85]
line [0.94, 1.94, 4.15, 6.26, 12.46, 26.00, 54.93, 113.14]
line [1.00, 2.11, 4.13, 6.24, 12.54, 27.13, 55.19, 115.26]
|
There was a problem hiding this comment.
Pull request overview
Updates @typegpu/react root lifecycle handling so that provider-owned (on-demand) TgpuRoot instances can be cleaned up when the <Root> provider unmounts, using deferred cleanup to remain compatible with React StrictMode effect replays.
Changes:
- Added an
unmount()lifecycle method to root context implementations and invoked it from<Root>viauseDeferredCleanup. - Introduced a destroyed flag in
OwnRootContextto prevent re-initialization after unmount and to attempt handling unmount during async initialization. - Refactored provider value creation to a single
rootCtxvariable used for both context and cleanup.
Comments suppressed due to low confidence (1)
packages/typegpu-react/src/core/root-context.tsx:156
useDeferredCleanuponly runs its effect once per mount (the callback is stabilized viauseEffectEvent), so the cleanup will only callunmount()on the latestrootCtxvalue at unmount time. If therootprop changes during the component lifetime (switching betweenExistingRootContextandOwnRootContext), the previous context’s resources won’t be cleaned up. Consider tying cleanup to the specificrootCtxinstance (e.g., effect keyed byrootCtxthat schedules cleanup for the previous instance) so context swaps don’t leak an initialized root.
export const Root = ({ children, root }: RootProps) => {
const [ownCtx] = useState(() => new OwnRootContext());
const existingRootCtx = useMemo(() => {
if (root) {
return new ExistingRootContext(root);
}
return undefined;
}, [root]);
const rootCtx = existingRootCtx ?? ownCtx;
useDeferredCleanup(() => {
rootCtx.unmount();
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c5964cd to
246107c
Compare
e4d31d2 to
1371236
Compare
1371236 to
f4f1720
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.
No description provided.