-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Ng class perf one map #48433
Ng class perf one map #48433
Conversation
3eeca64
to
81782fa
Compare
Putting is as "blocked" since there are 3 knows tests in G3 that are failing because of this PR. This is mostly due to the fact that those tests assert CSS class order: it is not guaranteed and changed in a subtle way. Investigating to decide if I should mimic the previous order or update the existing tests. |
f93d01f
to
910aaf2
Compare
Note: this PR will require G3 changes before landing (there are 3 failing tests that need to be updated). Having said this, the NgClass implementation seems correct and is ready for review. |
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.
@pkozlowski-opensource great work! 👍
The changes are looking good and easy to follow. Extra thanks for documenting the approach and the algorithm!
I've left a few minor comments, none of them are blockers :)
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.
Reviewed-for: size-tracking
6a4579d
to
c286199
Compare
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.
Looks great! 👍
c286199
to
9ed9d79
Compare
De-flaked TGP |
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.
👏 this looks excellent.
The new algorithm is clear, easy to follow, and seems very efficient.
9ed9d79
to
54573c8
Compare
54573c8
to
d463df0
Compare
Remove unnecessary curly brackets in tests.
This commit represents rewrite of the NgClass directive to address severe performance problem (excessive DOM mutation). The modified algorithm removes all the known performance clifs and has number of desirable properties: - it is shorter and (arguably) easier to follow; - drops usage of existing differs thus limiting dependencies on other part of the code without increasing size of the directive; - doesn't degrade any other performance metrics. Fixes angular#25518
d463df0
to
8fa9814
Compare
Caretaker note: the internal failing tests are not related and predate this PR. Also, I've got a passing, de-flaked TGP. |
This PR was merged into the repository by commit 5f21c6d. |
This commit represents rewrite of the NgClass directive to address severe performance problem (excessive DOM mutation). The modified algorithm removes all the known performance clifs and has number of desirable properties: - it is shorter and (arguably) easier to follow; - drops usage of existing differs thus limiting dependencies on other part of the code without increasing size of the directive; - doesn't degrade any other performance metrics. Fixes #25518 PR Close #48433
Remove unnecessary curly brackets in tests. PR Close #48433
This commit represents rewrite of the NgClass directive to address severe performance problem (excessive DOM mutation). The modified algorithm removes all the known performance clifs and has number of desirable properties: - it is shorter and (arguably) easier to follow; - drops usage of existing differs thus limiting dependencies on other part of the code without increasing size of the directive; - doesn't degrade any other performance metrics. Fixes #25518 PR Close #48433
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fanimations/15.1.0/15.1.1) | | [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fcommon/15.1.0/15.1.1) | | [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/15.1.0/15.1.1) | | [@angular/compiler-cli](https://github.com/angular/angular/tree/main/packages/compiler-cli) ([source](https://github.com/angular/angular)) | devDependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/15.1.0/15.1.1) | | [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fcore/15.1.0/15.1.1) | | [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fforms/15.1.0/15.1.1) | | [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/15.1.0/15.1.1) | | [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`15.1.0` -> `15.1.1`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/15.1.0/15.1.1) | --- ### Release Notes <details> <summary>angular/angular</summary> ### [`v15.1.1`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#​1511-2023-01-18) [Compare Source](angular/angular@15.1.0...15.1.1) ##### common | Commit | Type | Description | | -- | -- | -- | | [68ce4f6ab4](angular/angular@68ce4f6) | fix | Update `Location` to get a normalized URL valid in case a represented URL starts with the substring equals `APP_BASE_HREF` ([#​48489](angular/angular#48489)) | | [032b2bd689](angular/angular@032b2bd) | perf | avoid excessive DOM mutation in NgClass ([#​48433](angular/angular#48433)) | ##### core | Commit | Type | Description | | -- | -- | -- | | [dd54f6bd96](angular/angular@dd54f6b) | fix | makeEnvironmentProviders should accept EnvironmentProviders ([#​48720](angular/angular#48720)) | #### Special Thanks Alan Agius, Alex Rickabaugh, Andrew Scott, Aristeidis Bampakos, Bob Watson, Jens, Konstantin Kharitonov, Kristiyan Kostadinov, Matthieu Riegler, Paul Gschwendtner, Pawel Kozlowski, Vladyslav Slipchenko, ced, dario-piotrowicz, mgechev and ノウラ <!-- CHANGELOG SPLIT MARKER --> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDUuMyIsInVwZGF0ZWRJblZlciI6IjM0LjEwNS41In0=--> Co-authored-by: cabr2-bot <cabr2.help@gmail.com> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1739 Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org> Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org> Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Remove unnecessary curly brackets in tests. PR Close angular#48433
This commit represents rewrite of the NgClass directive to address severe performance problem (excessive DOM mutation). The modified algorithm removes all the known performance clifs and has number of desirable properties: - it is shorter and (arguably) easier to follow; - drops usage of existing differs thus limiting dependencies on other part of the code without increasing size of the directive; - doesn't degrade any other performance metrics. Fixes angular#25518 PR Close angular#48433
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit represents rewrite of the NgClass directive to address
severe performance problem (excessive DOM mutation). The modified
algorithm removes all the known performance clifs and has number of
desirable properties:
part of the code without increasing size of the directive;
algorithm notes
The NgClass directive uses the custom change detection algorithm for its inputs. The custom
algorithm is necessary since inputs are represented as complex object or arrays that need to be
deeply-compared.
This algorithm is perf-sensitive since NgClass is used very frequently and its poor performance
might negatively impact runtime performance of the entire change detection cycle. The design of
this algorithm is making sure that:
needed), even if references to bound objects change;
during the change detection cycle can result in GC pauses for some of the CD cycles).
The algorithm works by iterating over the set of bound classes, staring with [class] binding and
then going over [ngClass] binding. For each CSS class name:
changed;
and we can remove such class name from the internal data structures;
After iteration over all the CSS class names we've got data structure with all the information
necessary to synchronize changes to the DOM - it is enough to iterate over the state map, flush
changes to the DOM and reset internal data structures so those are ready for the next change
detection cycle.