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: remove element if ripples are disabled #8864

Conversation

devversion
Copy link
Member

Removes the ripple container element if ripples should be disabled for most of the Material components. This gives us a performance boost because the ripple events aren't being added if ripples are disabled.

In theory I would say that using *ngIf instead of [matRippleDisabled] is more appropriate in most of the components, but there are also cases where the ripple container can't be removed completely and for that, the [matRippleDisabled] binding is the right choice.

From a performance perspective, if someone often changes the disabled/disableRipple state, the event listeners will be removed and re-added. This seems to be like a trade-off. A possible solution for that would be to just keep the current implementation and just not register the events if the ripple directive is set to disabled initially (and afterwards register events if it turns enabled again).

Fixes #8854.

Removes the ripple container element if ripples should be disabled for most of the Material components. This gives us a performance boost because the ripple events aren't being added if ripples are disabled.

Fixes angular#8854
@devversion devversion added perf This issue is related to performance pr: needs review target: patch This PR is targeted for the next patch release labels Dec 7, 2017
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 7, 2017
@@ -1,7 +1,6 @@
<span class="mat-button-wrapper"><ng-content></ng-content></span>
<div matRipple class="mat-button-ripple"
<div matRipple class="mat-button-ripple" *ngIf="!_isRippleDisabled()"
Copy link
Member

Choose a reason for hiding this comment

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

Will this still register the events on the initial render if _isRippleDisabled it false on start-up?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the events won't be registered. And the directive won't be initialized either.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

I'm not sure whether the gains from not having the element at all outweigh the overhead of having to re-create everything. It might be better if we kept the element around, but only added/removed the event listeners when disabled.

@devversion
Copy link
Member Author

devversion commented Dec 7, 2017

@crisbeto Yeah I agree. That should be also better for performance in the cases where the element's disabled state is toggled pretty often (what I mentioned in the PR description)

I will try to work more on this PR. I think the only change would be to don't register the events if the ripples are disabled initially.

@AsafAgranat
Copy link

Events overhead aside, there's also a browser memory overhead, when disabled ripple elements remain in the DOM, as explained here. The short of it is that every ripple elements is painted on it's own DOM layer, bulking up the memory. Therefore ,disabled ripples should at least have their position: absolute changed to position: unset in order to spare the extra layers.

@devversion
Copy link
Member Author

@AsafAgranat This is a good point. Can we move that discussion to the new issue you've filed? I've just wanted to link those two threads because they have a related discussion.

(meaning that you just copy what you wrote to the new issue)

@AsafAgranat
Copy link

@devversion, sure. will do.

@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 Sep 9, 2019
@mmalerba mmalerba added the in progress This issue is currently in progress label Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement in progress This issue is currently in progress perf This issue is related to performance target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MatCheckbox] nested ripple registers events even if disableRipple is set.
6 participants