-
Notifications
You must be signed in to change notification settings - Fork 137
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
Stylish CPU/battery abuse on AJAX/DOM-heavy sites since 1.9.4 #24
Comments
@SteveJobzniak You can open
i have ~290ms |
@SteveJobzniak I'm working on better method - |
Another test with
~100ms |
@350d Thanks for researching this. The speed penalty was lower than I thought, but it's still annoying to have a browser extension "run" its own code constantly whenever the page does (very common) DOM work, even when the extension shouldn't have to do work. So it's good that you'll improve it. And your ideas for improvement sound very good!
So I guess you'd have to add all injected style DOM nodes to an array, and then whenever a node is removed from the page you just check if all of your injected styles still have their parentElement. And since you inject styles directly onto a top-level element (you use Very good method! With that, I can safely say that Stylish is doing its best to play nicely. 👍 |
@SteveJobzniak
So, single style inject will be fired only if exact style was removed |
@350d I've now read the 1.9.7 commit. It looks excellent! Happy to see that the new event now only performs work on the page when it has a reason to check if a style has been removed. This is a very nice optimization! :) Thank you! |
New issue to track this separately.
Problem:
document.addEventListener("DOMSubtreeModified", function(event) { console.log("- tree modified"); });
. And the situation is much worse on other sites.Needed:
Solution 1:
What this does:
clearTimeout()
makes sure that only 1 timer will ever exist at a time.Solution 2:
Synchronize the "checkStyles" to happen only before the screen is about to repaint.
requestAnimationFrame()
tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint.Anyway, if anyone has any better ideas for how to optimize the checkStyles() penalty on DOMSubtreeModified, please let us know!
@350d added the DOMSubtreeModified code because some sites insert DOM elements later than the initial load, and they aren't caught/styled on the first Stylish run (at page load). So he needed to add that constant checkStyles call. Now we just need a way to optimize it...
The text was updated successfully, but these errors were encountered: