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

perf(component): do not schedule render for synchronous events #3487

Merged

Conversation

markostanimirovic
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[x] Other... Please describe: Performance improvements

What is the current behavior?

The render scheduler unnecessarily schedules render/marks a component as dirty when synchronous events are emitted.

For instance, in the following example:

@Component({
  template: `
    <p>{{ obs$ | ngrxPush }}</p>
  `
})
export class TestComponent {
  obs$ = of(1, 2, 3);
}

The PushPipe will mark TestComponent as dirty (and schedule tick in zone-less mode) 4 times (3 next, and 1 complete event) which is not needed because all these events will be emitted synchronously, so the last value will be visible in the template without scheduling render/marking it as dirty.

What is the new behavior?

The render scheduler schedules render/marks a component as dirty only when asynchronous events are emitted.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@netlify
Copy link

netlify bot commented Jul 13, 2022

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 8a62fb7
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/62d1330078f04f00087b3745

Comment on lines -237 to -239
if (this.isMainViewCreated || this.isSuspenseViewCreated) {
this.renderScheduler.schedule();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need to schedule render for suspense events at all, because suspense events are synchronous.

@markostanimirovic markostanimirovic force-pushed the perf/component/sync-render-events branch from 768c7d9 to 8a62fb7 Compare July 15, 2022 09:27
@brandonroberts brandonroberts merged commit bb9071c into ngrx:master Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants