Skip to content

feat: add a flag in bootstrap to enable coalesce event to improve performance#30533

Closed
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
JiaLiPassion:test-coakescing-event
Closed

feat: add a flag in bootstrap to enable coalesce event to improve performance#30533
JiaLiPassion wants to merge 1 commit intoangular:masterfrom
JiaLiPassion:test-coakescing-event

Conversation

@JiaLiPassion
Copy link
Copy Markdown
Contributor

@JiaLiPassion JiaLiPassion commented May 17, 2019

add a new flag in BootstrapOptions to enable coalesce event to improve performance.

/**
 * Provides additional options to the bootstraping process.
 *
 *
 */
export interface BootstrapOptions {
  /**
   * Optionally specify which `NgZone` should be used.
   *
   * - Provide your own `NgZone` instance.
   * - `zone.js` - Use default `NgZone` which requires `Zone.js`.
   * - `noop` - Use `NoopNgZone` which does nothing.
   */
  ngZone?: NgZone|'zone.js'|'noop';
  
  // START<<<<<<<<<
  /**
   * Optionally specify if `NgZone` should be configure to coalesce
   * events.
   */
  ngZoneEventCoalescing?: true|false;
  // END<<<<<<<<<<<
}

The use case is something like this,

<div (click)="doSomethingElse()">
  <button (click)="doSomething()">click me</button>
</div>

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 run Change Detection once in this case.
By default, this new ngZoneEventCoalescing will be false, so nothing changed. If this option is being set to true, then only one change detection will be triggered async.

@JiaLiPassion JiaLiPassion requested a review from a team May 17, 2019 11:51
@jasonaden jasonaden added the area: core Issues related to the framework runtime label May 17, 2019
@ngbot ngbot Bot added this to the needsTriage milestone May 17, 2019
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch from b87b7a3 to b50e1ae Compare May 18, 2019 03:55
Copy link
Copy Markdown
Contributor

@mhevery mhevery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments.

Comment thread packages/core/src/application_ref.ts Outdated
Copy link
Copy Markdown
Contributor

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.

Suggested change
const ngZoneEventCoalescing = options ? options.ngZoneEventCoalescing : false;
const ngZoneEventCoalescing = (options && options.ngZoneEventCoalescing) || false;

Comment thread packages/core/src/application_ref.ts Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ngZoneOption?: NgZone | 'zone.js' | 'noop', ngZoneEventCoalescing?: boolean): NgZone {
ngZoneOption: NgZone | 'zone.js' | 'noop' | undefiend, ngZoneEventCoalescing: boolean): NgZone {

Comment thread packages/core/src/zone/ng_zone.ts Outdated
Comment thread packages/core/src/zone/ng_zone.ts Outdated
Comment thread packages/core/src/zone/ng_zone.ts Outdated
Comment thread packages/core/src/zone/ng_zone.ts Outdated
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks!

Comment thread packages/core/src/zone/ng_zone.ts Outdated
Comment thread packages/core/src/zone/ng_zone.ts Outdated
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

Comment thread packages/core/src/application_ref.ts Outdated
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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?

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented May 31, 2019

Need to run bazel run //tools/public_api_guard:core_api.accept

@JiaLiPassion JiaLiPassion requested a review from a team May 31, 2019 15:30
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@mhevery, I fixed several issues, now all tests passed, (expect the case of integration file-size-limit), I will continue to add test cases, could you run this version in g3? Thanks!

@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch from 36e5659 to 38a3b0b Compare June 6, 2019 16:43
@JiaLiPassion JiaLiPassion requested a review from a team June 6, 2019 16:43
@JiaLiPassion JiaLiPassion changed the title WIP: test coalesce event feat: test coalesce event Jun 6, 2019
@JiaLiPassion JiaLiPassion changed the title feat: test coalesce event feat: add a flag in bootstrap to enable coalesce event to improve performance Jun 6, 2019
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

Need wait angular/zone.js#1239 to be merged. So the integration test can pass.

@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch 2 times, most recently from e45f1fc to b0ec7b4 Compare July 25, 2019 04:54
@JiaLiPassion JiaLiPassion requested a review from a team July 25, 2019 04:54
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch from b0ec7b4 to 1bc95b4 Compare July 26, 2019 20:33
@JiaLiPassion JiaLiPassion requested a review from a team July 26, 2019 20:33
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch 2 times, most recently from 665c1ae to 0e681c1 Compare July 26, 2019 21:32
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch 5 times, most recently from df3dd8c to 5911811 Compare August 30, 2019 06:23
@JiaLiPassion JiaLiPassion requested a review from mhevery August 30, 2019 15:06
@matsko matsko added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Oct 17, 2019
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch 3 times, most recently from 8f6842d to 8f3b6ba Compare October 19, 2019 04:22
@JiaLiPassion JiaLiPassion removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Oct 19, 2019
@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@matsko, I have updated the PR and now the API will not have any changes, and g3 should be ok, please review, thank you!

Comment thread packages/core/src/application_ref.ts Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* colesced and the change detection will be triggered multiple times.
* coalesced and the change detection will be triggered multiple times.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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.

@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch 2 times, most recently from 0743288 to be89686 Compare October 19, 2019 13:50
@JiaLiPassion JiaLiPassion force-pushed the test-coakescing-event branch from be89686 to 90ca4cb Compare October 19, 2019 14:09
@matsko matsko added the action: merge The PR is ready for merge by the caretaker label Oct 21, 2019
@kara kara added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 22, 2019
@kara kara requested a review from IgorMinar October 22, 2019 19:17
@JiaLiPassion JiaLiPassion requested a review from mhevery October 26, 2019 02:11
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Oct 28, 2019

presubmit

@mhevery mhevery removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 29, 2019
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Nov 5, 2019

MERGE_ASSISTANCE: Please merge by itself as this is high risk.

@AndrewKushnir
Copy link
Copy Markdown
Contributor

Since this change is a high risk (as Misko mentioned), I've started a Global VE presubmit as well (and a Blueprint one).

@atscott
Copy link
Copy Markdown
Contributor

atscott commented Nov 5, 2019

This was merged to master only. @mhevery @JiaLiPassion is that good or did you also need this in the patch branch?

@naveedahmed1
Copy link
Copy Markdown
Contributor

Should this provide any benefit on server, I mean in case of SSR/Universal?

@trotyl
Copy link
Copy Markdown
Contributor

trotyl commented Nov 7, 2019

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.

@JiaLiPassion
Copy link
Copy Markdown
Contributor Author

@atscott, I am not sure about whether this need to be merged to patch branch, @mhevery , please confirm, thanks!

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: high target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.