New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[labs/ssr] fix patching of patched directives memory leak #4528
Conversation
🦋 Changeset detectedLatest commit: 7918f2f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
The size of lit-html.js and lit-core.min.js are as expected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might not be the best fix but it's a very minimal patch that fixes a bad behavior.
I'm in favor of doing something quick to fix this, and deliberating on a better architecture for using private ssr support.
For additional context, I'm not declaring bankruptcy on the better solution. But this solution is super small, fixes the leak, and doesn't block the better solution. |
Went with the better approach in the end: #4515 |
Context
This has been split out of #4515 which explored a performant and more optimal fix. However, this revealed some possible other issues, e.g. #4527.
This change is a super tiny incremental fix which resolves the leak, and leaves the door open for future improvements.
How does this resolve the leak?
The leak occurs due to directive constructors being re-used. However on re-use, the constructor is patched and isn't in the key of the
WeakMap
. The leak is then caused by patching the directive by applying another patch mixin. This occurs over and over. Because each patched directive extends the prior patched directive, they can never be cleaned up and on each SSR render you end up with directives being extended an additional time.By adding the patched directive into the key, when the patched directive is encountered, we no longer patch it again. Thus fixing the leak.
Test plan
This was manually tested with #4514
Risk
The risk of this is tiny since the change is laser focused, and results in a patch bump to only SSR (Whilst the solution explored in #4515 requires
lit-html
to be bumped).Credit to @augustjk for this much simpler fix that my initial branding of the patched directive.