Created attachment 130198 [details] Slow down warning SUMMARY I'm often getting the attached warning when browsing some gitlab.com pages, especially on diff or merge request pages. STEPS TO REPRODUCE I don't really know, it seems to happen more on medium to large diffs, but it's not consistent on any given page. OBSERVED RESULT Frozen tab for a few seconds. EXPECTED RESULT No warning. SOFTWARE/OS VERSIONS Linux/KDE Plasma: Kubuntu 20.04 KDE Plasma Version: 5.18.5 KDE Frameworks Version: 5.68.0 Qt Version: 5.12.8 Firefox: Nightly 80.0a1 (2020-07-16) (64-bit) Plasma Integration: 1.7.5
Should be mitigated by https://invent.kde.org/plasma/plasma-browser-integration/-/commit/a3f400c8589eb8ec52f3f377d96b004ffd29221c
Mitigated or fully resolved?
Mitigated. GitLab isn't particularly efficient in how they do the Ajax and page rendering, so it'll still trip the mutation observer excessively.
I don't know the ins and outs of this extension at all, but wouldn't it be possible to make the mutation observer use requestIdleCallback to schedule that work for a later time when the browser is less busy? The addedNodes loop would just need to make sure the nodes are still attached.
Otherwise, I don't know if this comment (https://stackoverflow.com/a/38882022) is still true to this day, but maybe querySelectorAll should be avoided? A quick benchmark (https://jsperf.com/getelementsby-vs-queryselectorall/7) on my Firefox shows getElementsBy* being at least 100 times faster, Chrome also shows lower but similar results, hopefully it'll be the same on real world pages.
Very good ideas! The code is admittedly a bit messy. If you want you can give it a poke, here's the relevant code: https://invent.kde.org/plasma/plasma-browser-integration/-/blob/master/extension/content-script.js#L557
So I've been running a custom build including both patches for 3 days, I don't know if it's a placebo effect or not, but Firefox feels much smoother and responsive across the board now, and I've seen no issue so far. Do you think it's worth implementing the idle suggestion or is it enough as it is? I don't know if it's worth the complexity.
And I spoke too soon :) I just had it for a brief moment on a massive diff on gitlab, but it's definitely an improvement as it's not stuck for several seconds. I guess my previous question still stands.