-
Notifications
You must be signed in to change notification settings - Fork 191
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
Use _private
instead of #private
properties
#1335
Conversation
The updates to the template compiler made in support of strict mode introduced a number of uses of private class fields, some of them in hot paths. Although all supported versions of Node support private class fields, `tsc` transpiles private class fields to `WeakMap`s for all values of `target` lower than `ESNEXT`. As a result, the use of private class fields results in dramatically higher memory usage and garbage collection than in the previous version of the template compiler. This in turn causes at least a large portion of the regression noted in [emberjs/ember.js#19750][1]. [1]: emberjs/ember.js#19750 Here, we replace *all* private class fields with `_` private fields, which substantially (thought not 100%) closed the gap with the original. Co-authored-by: Brenden Palmer <[email protected]>
c1ec710
to
80eed34
Compare
I don't think we need to do something else here. All of this code is private already and we really don't have to protect ourselves to the extent that private fields are a fundamental requirement. |
@chriskrycho - Can you test this against the reproduction created in https://github.com/brendenpalmer/repro-ember-3-25-template-regression? I'm happy to help set up a simplified pipeline to test those templates in just @glimmer/syntax (vs requiring the full ember-template-compiler)... |
@rwjblue agreed re: not needing to do those things; just wanted to call them out for context historically. If you have that simplified pipeline that'd be great. I will note that we tested these changes against the LinkedIn.com app, and this fix got us about 22% of our total degradation back. Which is good! …but also means that we will need to find another 78% elsewhere. |
Using this PR on the repro repo, here are the timings reported:
Here, I'll add some stats from our build analysis internally later as well. |
This is a really nice improvement (looks like it brings us back to right around 2x slower than the 3.24 speed vs the current 5.5x slower than 3.24 of master)! |
This is definitely a good improvement, so landing it will help! However, I'm also going to keep pushing, as it's still a non-trivial regression for our app. Results from our appHere are results comparing our app's behavior on 3.24, 3.28, and 3.28 with this patch. Some definitions:
3.24
3.28
3.28 with this patch
SummaryThis change helps, but it helps our app significantly less than it helps in the benchmark for cold builds:
We currently suspect this is a function of the fact that the new work still load ends up including more memory pressure, and thus causing more GCs, causing new allocations, or both, so in a larger app: we have more than 2.5× the templates in our app and ~5.67× as many lines of template code. |
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.
Thanks for gathering those numbers @chriskrycho! Definitely still room to grow, but this is still a nice improvement. So it's good to land...
The updates to the template compiler made in support of strict mode introduced a number of uses of private class fields, some of them in hot paths. Since
tsc
currently transpiles private class fields toWeakMap
s for all values oftarget
lower thanESNEXT
, this results in dramatically higher memory usage and garbage collection than in the previous version of the template compiler. This in turn causes at least a large portion of the regression noted in emberjs/ember.js#19750.Here, we replace all private class fields with
_
private fields, which substantially (thought not 100%) closed the gap with the original.As alternatives here, we could:
HbsSpan
)cc. @brendenpalmer @rwjblue @krisselden