Skip to content

perf(core): avoid unnecessary callbacks in after render hooks#52292

Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:after-render-cleanup
Closed

perf(core): avoid unnecessary callbacks in after render hooks#52292
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:after-render-cleanup

Conversation

@crisbeto
Copy link
Member

A few performance improvements and code cleanups in the after render hooks:

  1. We were wrapping each destroy callback in another callback, because destroy was typed as |undefined. This is unnecessary, because the callback is guaranteed to exist. These changes pass the destroy function around directly and avoid the additional callback.
  2. In server platforms we were recreating a noop AfterRenderRef on each invocation. We can save some memory by returning the same one.
  3. Reworks the AfterRenderCallback so that it injects NgZone and ErrorHandler itself, instead of expecting them to be passed in. This reduces the amount of repetition in the code.

A few performance improvements and code cleanups in the after render hooks:
1. We were wrapping each `destroy` callback in another callback, because it was typed as `|undefined`. This is unnecessary, because the callback is guaranteed to exist. These changes pass the `destroy` function around directly and avoid the additional callback.
2. In server platforms we were recreating a noop `AfterRenderRef` on each invocation. We can save some memory by returning the same one.
3. Reworks the `AfterRenderCallback` so that it injects `NgZone` and `ErrorHandler` itself, instead of expecting them to be passed in. This reduces the amount of repetition in the code.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: rc This PR is targeted for the next release-candidate labels Oct 20, 2023
@crisbeto crisbeto marked this pull request as ready for review October 20, 2023 08:17
@ngbot ngbot bot added this to the Backlog milestone Oct 20, 2023
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

👍

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 20, 2023
@dylhunn
Copy link
Contributor

dylhunn commented Oct 23, 2023

This PR was merged into the repository by commit cce3743.

@dylhunn dylhunn closed this in cce3743 Oct 23, 2023
dylhunn pushed a commit that referenced this pull request Oct 23, 2023
A few performance improvements and code cleanups in the after render hooks:
1. We were wrapping each `destroy` callback in another callback, because it was typed as `|undefined`. This is unnecessary, because the callback is guaranteed to exist. These changes pass the `destroy` function around directly and avoid the additional callback.
2. In server platforms we were recreating a noop `AfterRenderRef` on each invocation. We can save some memory by returning the same one.
3. Reworks the `AfterRenderCallback` so that it injects `NgZone` and `ErrorHandler` itself, instead of expecting them to be passed in. This reduces the amount of repetition in the code.

PR Close #52292
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 23, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…r#52292)

A few performance improvements and code cleanups in the after render hooks:
1. We were wrapping each `destroy` callback in another callback, because it was typed as `|undefined`. This is unnecessary, because the callback is guaranteed to exist. These changes pass the `destroy` function around directly and avoid the additional callback.
2. In server platforms we were recreating a noop `AfterRenderRef` on each invocation. We can save some memory by returning the same one.
3. Reworks the `AfterRenderCallback` so that it injects `NgZone` and `ErrorHandler` itself, instead of expecting them to be passed in. This reduces the amount of repetition in the code.

PR Close angular#52292
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 target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments