Skip to content
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

Backport: Cache head getter in PathExpressionImplV1 #1358

Merged
merged 6 commits into from
Oct 22, 2021

Conversation

chriskrycho
Copy link
Contributor

Backport for #1344.

chriskrycho and others added 6 commits October 22, 2021 09:47
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 <brendenpalmer@gmail.com>
Previously, this field was being assigned twice: once via direct
assignment in the constructor, and once via the `copy` (previously) or
`Object.assign` (now in this stream of changes) call.
The project already has handling for using `Object.assign` if available
and a polyfill if not; use it!
The `scope` info here is entirely unused in the Glimmer codebase. It may
be used in some AST transforms, but this is fairly unlikely, since it
has only been available since Ember 3.16. Profiling template compilation
highlighted the recursive walking of the whole tree for locals in scope
during syntax parsing as a major cost in CPU usage, so the hope is that
removing this will help.
This is one of the hot paths during normalization, and it in turn calls
the *hottest* paths of normalization (`hbsPosFor` and `hbsCharFor`).
Adding this cache improves performance againt the baseline by nearly 50%
of the current delta:

|           variant            | average | min  | max  |
| ---------------------------- | ------- | ---- | ---- |
| @glimmer/compiler@0.65.3     | 6901.4  | 6812 | 6944 |
| @glimmer/compiler@master     | 9000.4  | 8925 | 9041 |
| @glimmer/compiler@experiment | 8144.8  | 8078 | 8240 |
@rwjblue rwjblue merged commit ae2b7c0 into glimmerjs:release-0-80 Oct 22, 2021
@chriskrycho chriskrycho deleted the backport-cache-head branch October 22, 2021 16:17
@rwjblue rwjblue added the bug label Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants