fix(ember): Stop retaining component render payloads in beforeEntries - #23052
Merged
s1gr1d merged 3 commits intoAug 11, 2026
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yashschandra
requested review from
nicohrubec and
s1gr1d
and removed request for
a team
August 5, 2026 10:22
Contributor
|
👋 @nicohrubec, @s1gr1d — Please review this PR when you get a chance! |
s1gr1d
reviewed
Aug 10, 2026
| now: timestampInSeconds(), | ||
| }; | ||
| beforeEntries[payload.object] = info; | ||
| beforeEntries.set(payload.object, info); |
Member
There was a problem hiding this comment.
L: Maybe it would make sense here to use a WeakMap and use the payload as the key. We don't need the info, when the payload is already garbage collected, right?
Member
There was a problem hiding this comment.
👍 I think moving this to a weakmap is likely the easiest solution here?
Member
There was a problem hiding this comment.
(I think it's still ok to remove the entries as well, but a weak map ensures nothing can linger around if something is not called etc)
Per review on getsentry#23052, switch RenderEntries from Map<string, RenderEntry> to WeakMap<Payload, RenderEntry>. Keying weakly on the payload object guarantees nothing lingers even if a render's `after` hook is never called; the prompt delete is kept so a long-lived payload doesn't hold a stale entry between renders. Ember passes the same payload object to a subscriber's before/after hooks, so identity-based lookup is safe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
s1gr1d
approved these changes
Aug 11, 2026
s1gr1d
enabled auto-merge (squash)
August 11, 2026 07:34
mydea
pushed a commit
that referenced
this pull request
Aug 11, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #23052 Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com>
JPeer264
pushed a commit
that referenced
this pull request
Aug 12, 2026
…#23052) Before submitting a pull request, please take a look at our [Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md) guidelines and verify: - [x] If you've added code that should be tested, please add tests. - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). - [x] Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked. ## Problem `_instrumentComponents` subscribes to Ember's `render.component` (and optionally `render.getComponentDefinition`) instrumentation and stores `{ payload, now }` into a module-scope `beforeEntries` map keyed by `payload.object` (a per-component-instance GUID). `processComponentRenderAfter` reads the entry but never removes it, so every instrumented component render is retained for the lifetime of the page. Since the render `payload` references the component instance (`view`), this pins each destroyed component **and everything it references**. In our Ember app (Customer.io Journeys) this retained every destroyed message-composer graph when users switched between wizard steps — **~34 MB of unreclaimable heap per step switch**, measured in Chrome with `--js-flags=--expose-gc` and confirmed via heap-snapshot retainer paths ending at the instrumentation subscriber's `beforeEntries` closure: ``` (GC roots) → module context → subscribers → before closure → beforeEntries → entry → payload → view (component) → parent component graph (~34 MB / cycle) ``` ## Fix - Convert `RenderEntries` to a `WeakMap` keyed on the render `payload` object itself (per review feedback). This guarantees an entry can never outlive its payload, even if a render's `after` hook is never called. Ember's `@ember/instrumentation` passes the same payload object to a subscriber's `before` and `after` hooks, so identity-based lookup is safe; `payload.object` (a string) can't key a `WeakMap`, so the entry no longer needs to store the payload at all. - Still delete the entry in `processComponentRenderAfter` once the render completes, so a long-lived payload doesn't hold a stale entry between renders. - Export `_processComponentRenderBefore` / `_processComponentRenderAfter` (following the existing `_`-prefixed pattern used by `instrumentEmberAppInstanceForPerformance`) and add unit tests covering: entry removal on completion (both below and above `minimumComponentRenderDuration`), and that an `after` without a matching `before` leaves other in-flight entries untouched. Verified in the affected app: with this change all destroyed component graphs become collectable and back-to-back heap snapshots across step-switch cycles show only ~0.5 MB/cycle of JIT-code growth instead of ~34 MB/cycle of retained objects. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Yash Suresh Chandra <yashschandra@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
JPeer264
pushed a commit
that referenced
this pull request
Aug 12, 2026
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #23052 Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com>
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.
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).Problem
_instrumentComponentssubscribes to Ember'srender.component(and optionallyrender.getComponentDefinition) instrumentation and stores{ payload, now }into a module-scopebeforeEntriesmap keyed bypayload.object(a per-component-instance GUID).processComponentRenderAfterreads the entry but never removes it, so every instrumented component render is retained for the lifetime of the page.Since the render
payloadreferences the component instance (view), this pins each destroyed component and everything it references. In our Ember app (Customer.io Journeys) this retained every destroyed message-composer graph when users switched between wizard steps — ~34 MB of unreclaimable heap per step switch, measured in Chrome with--js-flags=--expose-gcand confirmed via heap-snapshot retainer paths ending at the instrumentation subscriber'sbeforeEntriesclosure:Fix
RenderEntriesto aWeakMapkeyed on the renderpayloadobject itself (per review feedback). This guarantees an entry can never outlive its payload, even if a render'safterhook is never called. Ember's@ember/instrumentationpasses the same payload object to a subscriber'sbeforeandafterhooks, so identity-based lookup is safe;payload.object(a string) can't key aWeakMap, so the entry no longer needs to store the payload at all.processComponentRenderAfteronce the render completes, so a long-lived payload doesn't hold a stale entry between renders._processComponentRenderBefore/_processComponentRenderAfter(following the existing_-prefixed pattern used byinstrumentEmberAppInstanceForPerformance) and add unit tests covering: entry removal on completion (both below and aboveminimumComponentRenderDuration), and that anafterwithout a matchingbeforeleaves other in-flight entries untouched.Verified in the affected app: with this change all destroyed component graphs become collectable and back-to-back heap snapshots across step-switch cycles show only ~0.5 MB/cycle of JIT-code growth instead of ~34 MB/cycle of retained objects.
🤖 Generated with Claude Code