fix: plug remaining per-render leaks in converted component props - #5716
Open
jkelleyrtp wants to merge 3 commits into
Open
fix: plug remaining per-render leaks in converted component props#5716jkelleyrtp wants to merge 3 commits into
jkelleyrtp wants to merge 3 commits into
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Follow-up to #5711: a counting-allocator harness run over ~28 prop/macro permutations found three more classes of unbounded per-render growth that the child-owned-props fix didn't cover.
1. Sync-storage allocations escape the props owner. The generated props owner was a single
Owner<UnsyncStorage>, andwith_owneronly overrides the thread-local owner for one storage type. AnySyncStorageallocation made during a prop conversion fell back to the parent scope's sync owner and leaked once per render:ReadSignal<T, SyncStorage>props converted from sync mapped signals (~2.5 KB/render in the harness — the exact Memory leak #5671 bug, sync flavor)#[props(default = Store::new(..))]store props (StoreSubscriptionsis alwaysCopyValue<_, SyncStorage>; ~10 KB/render)Fix: props now hold a
PropsOwner { unsync: Owner<UnsyncStorage>, sync: Owner<SyncStorage> }and conversions run underwith_props_owner, which overrides both thread-local owners. Updated the props macro codegen and the hand-expandedSuspenseBoundaryPropsbuilder.2.
point_tomemoization accumulates stale subscriptions. Props likeval: ReadSignal<String>set from a plain value create a fresh signal (with a fresh subscriber list) every parent render. Memoization then runsold.point_to(new), which did:Since the memoized child never reruns, its
ReactiveContextnever clears subscriptions, so it accumulated one dead subscriber-listArcper render (~5 KB/render for 20 children). Fix: addedReactiveContext::unsubscribe, andReadSignal::point_to/Signal::point_tonow drop the subscription to the old list after moving subscribers to the new one (guarded bySubscribers::ptr_eqso pointing at a signal sharing the same list — e.g. mapped signals over the same source — doesn't unsubscribe the child from a live list).3.
#[props(into)]conversions the macro can't classify run in the parent owner.child_owned_typematches on the written type name, so a signal behind a type alias (e.g.type AliasSignal = ReadSignal<usize>;+#[props(into)]) was treated as a regular into-field and converted outsidewith_props_owner(~6 KB/render). Fix:has_child_owned_fieldswas broadened tohas_owned_fields(signal-like,auto_into, or a non-blank default), and allintoconversions and default expressions now run under the props owner. Structs with only trivial fields (children, plainOption<T>props, blankDefault::default()defaults) still skip owner creation, so the common paths pay no extra allocation.Verified: ~28 permutations flat over 2000 rerenders (mapped store/signal props across Store/ReadStore/WriteStore/ReadSignal/WriteSignal/ReadOnlySignal, sync storage, defaults, aliases, callbacks, Option handlers, spread/extends attrs, SuspenseBoundary fallbacks, pass-through chains, element listeners, use_callback). Added
packages/core/tests/props_memory_leak.rsas regression coverage.Known remaining footgun (not fixable in the macro): explicitly converting in the render body, e.g.
OptChild { id: Store::from(item) }orReadSignal::from(sig)for anOption<...>-typed prop, allocates under the parent scope and still grows per render — the conversion happens before the setter, same class as callingSignal::newin a render body. Option-wrapped signal/store props currently have noSuperFromimpls, so the macro never sees an unconverted value for them.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/893180b21fbb4d40874a9ec85d17f4b3
Requested by: @jkelleyrtp