inuyaksa / jquery.nicescroll

nicescroll plugin for jquery - scrollbars like iphone/ipad
https://nicescroll.areaaperta.com/
3.6k stars 1.67k forks source link

DOMAttrModified is deprecated and should not be listened for #643

Closed brycepj closed 7 years ago

brycepj commented 7 years ago

At my company, we are seeing some crazy perf problems in non-webkit browsers that emanate from nicescroll's listening for deprecated mutation events.

Here's what the profiler looks like for a 200ms period in Firefox, for example. I see 200-ish calls of setTimeout and associated callbacks during this period.

screen shot 2016-12-12 at 5 57 19 pm

According to MDN:

The mutation events have been marked as deprecated in the DOM Events specification, as the API's design is flawed (see details in the "DOM Mutation Events Replacement: The Story So Far / Existing Points of Consensus" post to public-webapps).

Mutation Observers are the proposed replacement for mutation events in DOM4. They are expected to be included in Firefox 14 and Chrome 18.

The practical reasons to avoid the mutation events are performance issues and cross-browser support.

And to the point most directly:

Adding DOM mutation listeners to a document profoundly degrades the performance of further DOM modifications to that document (making them 1.5 - 7 times slower!). Moreover, removing the listeners does not reverse the damage.

The performance effect is limited to the documents that have the mutation event listeners. source