Closed Bug 1787072 Opened 2 years ago Closed 2 years ago

Element.getBoundingClientRect performance on CloudFlare mirage script is horrible on pages with lots of images, unlike Chrome.

Categories

(Core :: DOM: CSS Object Model, defect)

defect

Tracking

()

RESOLVED FIXED
106 Branch
Webcompat Priority P2
Tracking Status
firefox106 --- fixed

People

(Reporter: twisniewski, Assigned: emilio)

References

(Regressed 1 open bug, )

Details

Attachments

(1 file)

This bug is a spin-off of the webcompat.com issue: https://github.com/webcompat/web-bugs/issues/108157

Based on my diagnosis there, it seems that Chrome may have added performance optimizations to getBoundingClientRect which make it perform quickly with CloudFlare's Mirage script on image-heavy sites like https://gamepress.gg/feheroes/weapon-skills

I see no evidence of Mirage doing something different in Chrome, so I worry that this significant performance difference may be affecting other sites using Mirage. (It causes a slow script warning on my 2019 Intel macbook in responsive design mode; I can only imagine how long some phones would take to finish the task on Fenix).

Do you have a profile we could look at? How do I reproduce the issue?

Flags: needinfo?(twisniewski)

Oh, I think I managed to see it (there's another jank source from an ad script...)

I can make another profile if it will still help, but my profile's time almost all went down a JS stack trace leading to their isWithinViewport function, with all that time basically spent in Element.getBoundingClientRect, and Reflow. I caught it by opening the page in responsive design mode on my macbook, waiting a moment to confirm that the tab was "frozen", starting profiling, then stopping it a few seconds later before the slow script prompt appeared.

Flags: needinfo?(twisniewski)
Assignee: nobody → emilio
Attachment #9291458 - Attachment description: WIP: Bug 1787072 - Avoid useless reframes setting the src attribute of a broken image that already has an image frame. r=#style → Bug 1787072 - Avoid useless reframes setting the src attribute of a broken image that already has an image frame. r=#style,#layout-reviewers
Status: NEW → ASSIGNED

This is not about optimizing getBoundingClientRect or what not. The page is doing img.src = ...; img.getBoundingClientRect();, and we're invalidating too much after the src setter which cause getBoundingClientRect() to reflow.

There are two issues here. The first one is that that invalidation is useless in this case. That's fixed by comment 4. The other is that setting src should trigger an async image load (bug 1076583). That's a bit more tricky / annoying to fix, I suspect.

See Also: → 1076583

For the record I also see getBoundingClientRect performance possibly affecting another webcompat bug today, based on the performance profile at https://github.com/webcompat/web-bugs/issues/107388. I'm not sure if they're the same issue however, based on that profile spending the time in Styles/Style computation rather than in Reflow.

Just for the record, I tried a local build with and without this patch, and I couldn't reproduce the slow script warning with the patch applied (testing in responsive design mode). So this should definitely help on the original issue, at least.

Pushed by ealvarez@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3f26214c64a4
Avoid useless reframes setting the src attribute of a broken image that already has an image frame. r=dholbert
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 106 Branch
Regressions: 1789828
Regressions: 1797798
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: