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
feat: add a flag in bootstrap to enable coalesce event to improve performance #30533
Conversation
b87b7a3
to
b50e1ae
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.
Minor comments.
packages/core/src/application_ref.ts
Outdated
@@ -249,7 +251,8 @@ export class PlatformRef { | |||
// So we create a mini parent injector that just contains the new NgZone and | |||
// pass that as parent to the NgModuleFactory. | |||
const ngZoneOption = options ? options.ngZone : undefined; | |||
const ngZone = getNgZone(ngZoneOption); | |||
const ngZoneEventCoalescing = options ? options.ngZoneEventCoalescing : false; |
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.
I think this is easier to read.
const ngZoneEventCoalescing = options ? options.ngZoneEventCoalescing : false; | |
const ngZoneEventCoalescing = (options && options.ngZoneEventCoalescing) || false; |
packages/core/src/application_ref.ts
Outdated
@@ -340,14 +343,17 @@ export class PlatformRef { | |||
get destroyed() { return this._destroyed; } | |||
} | |||
|
|||
function getNgZone(ngZoneOption?: NgZone | 'zone.js' | 'noop'): NgZone { | |||
function getNgZone( | |||
ngZoneOption?: NgZone | 'zone.js' | 'noop', ngZoneEventCoalescing?: boolean): NgZone { |
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.
ngZoneOption?: NgZone | 'zone.js' | 'noop', ngZoneEventCoalescing?: boolean): NgZone { | |
ngZoneOption: NgZone | 'zone.js' | 'noop' | undefiend, ngZoneEventCoalescing: boolean): NgZone { |
packages/core/src/zone/ng_zone.ts
Outdated
function forkInnerZoneWithAngularBehavior(zone: NgZonePrivate) { | ||
declare const global: any; | ||
|
||
const _global: any = typeof window !== 'undefined' ? |
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.
import global from core/src/util
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.
got it, thanks!
packages/core/src/zone/ng_zone.ts
Outdated
// so we need to cancel that and schedule a new one, or maybe we can just | ||
// skip. | ||
// option1 : cancel and reschedule | ||
// option2: just return |
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.
Just return, I don't think there is a value in canceling it.
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.
Got it!
@@ -199,6 +199,8 @@ export interface BootstrapOptions { | |||
* - `noop` - Use `NoopNgZone` which does nothing. | |||
*/ | |||
ngZone?: NgZone|'zone.js'|'noop'; | |||
|
|||
ngZoneEventCoalescing?: boolean; |
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.
Needs public API docs here.
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.
can you add docs explaining what this does?
Need to run |
@mhevery, I fixed several issues, now all tests passed, (expect the case of |
36e5659
to
38a3b0b
Compare
Need wait angular/zone.js#1239 to be merged. So the |
e45f1fc
to
b0ec7b4
Compare
b0ec7b4
to
1bc95b4
Compare
665c1ae
to
0e681c1
Compare
df3dd8c
to
5911811
Compare
@matsko, I have updated the PR and now the API will not have any changes, and g3 should be ok, please review, thank you! |
packages/core/src/application_ref.ts
Outdated
* change detection only once. | ||
* | ||
* By default, this option will be false. So the events will not be | ||
* colesced and the change detection will be triggered multiple times. |
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.
* colesced and the change detection will be triggered multiple times. | |
* coalesced and the change detection will be triggered multiple times. |
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 the review, updated.
}; | ||
} | ||
|
||
var nativeRequestAnimationFrame = getNativeRequestAnimationFrame().nativeRequestAnimationFrame; |
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.
I just stumbled over this PR. Out of curiosity: is it intentional that we introduce a new side-effect global call here?
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.
you are right, I should not add a side-effect here, I just updated the PR to move the call inside ngZone initialize call.
0743288
to
be89686
Compare
…on to improve performance
be89686
to
90ca4cb
Compare
…on to improve performance (angular#30533) PR Close angular#30533
… detection to improve performance (angular#30533) (angular#33230) This reverts commit 21c1e14. PR Close angular#33230
MERGE_ASSISTANCE: Please merge by itself as this is high risk. |
Since this change is a high risk (as Misko mentioned), I've started a Global VE presubmit as well (and a Blueprint one). |
This was merged to master only. @mhevery @JiaLiPassion is that good or did you also need this in the patch branch? |
Should this provide any benefit on server, I mean in case of SSR/Universal? |
There is little chance for DOM events to be triggered on server, unless you manually dispatch them. |
…on to improve performance (angular#30533) PR Close angular#30533
…on to improve performance (angular#30533) PR Close angular#30533
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. |
add a new flag in
BootstrapOptions
to enable coalesce event to improve performance.The use case is something like this,
It turns out that as the click event bubbles from the towards the root document it triggers change detection on each listener. This example shows the phenomena in interactive form. Notice that clicking on the will run the change detection twice. Once for the and once for the
So with this PR, we have this new option to let
ngZone
only runChange Detection
once in this case.By default, this new
ngZoneEventCoalescing
will befalse
, so nothing changed. If this option is being set to true, then only one change detection will be triggered async.