-
Notifications
You must be signed in to change notification settings - Fork 6.8k
perf(material/tooltip): Defer injection of injectables not needed unt… #30440
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we know what the impact of this is? These are likely already instantiated by the time the tooltip is rendered.
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.
The impact is to move a small cost (resolving the injectable) from instantiation time to if/when the tooltip is first shown.
The cost should be small enough that it's not noticeable when showing a tooltip, but does add up during instantiation if lots of MatTooltip instances are being created (imagine a big screen full of content that has tooltips).
Further, most MatTooltip instances will be created but not shown, so on net this reduces the cpu burden of MatTooltip, even if only a smidge.
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.
From an example profiler run:
Of the 15.3ms spent instantiating MatTooltip instances, 8.8ms was spent in calls to inject(). This PR removes 1/3 of the inject calls, so we might naively guess that it saves about 3ms, or almost 1/5 of overall MatTooltip instantiation time.
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.
Is that 15ms per tooltip instance or 15ms for all the instances on the page? I would be hesitant with sprinkling this pattern across the codebase since it makes the component harder to navigate IMO. The tooltip is already a bit messy because of all the manual even bindings.
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 is across many instances, which is sort of the point.
For the page I'm profiling, a big mat-table, the only Directive/component whose factory/constructor took more time is MatCell (3.3% of table render time), and there are a lot more of those (alas chrome's profiler doesn't give exact numbers). MatTooltip's factory took 1.3%, which is quite significant considering how much else is being rendered.
Note: I separately asked Jeremy and Andrew if I could add a lazy version of inject() to the framework and they suggested keep with this pattern instead for the time being.
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.
Alright, I think it makes sense for commonly used components like
MatTooltip
, but I don't think that we should apply it everywhere.