Bad performance with deeply-nested display: grid elements
Categories
(Core :: Layout: Grid, defect, P3)
Tracking
()
People
(Reporter: alexandre.rico, Assigned: sefeng)
References
(Regressed 1 open bug)
Details
(Keywords: perf, perf:resource-use, testcase)
Attachments
(5 files)
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
Steps to reproduce:
This is a test file I wrote so you can reproduce the bug.
Basically when you open this HTML in Firefox, it freeze the browser and the computer CPU usage go to 100%.
Delete 3 <div> and it work fine.
The more you had <div> the longer it take to render.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div style="padding: 10px; display: grid; grid-template-rows: min-content auto;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<div style="display: grid;">
<span>TEST</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Actual results:
Taking way too long to display this HTML. And my CPU goes to 100% compare to Chrome with the same file.
Expected results:
Render immediately the HTML.
Comment 2•5 years ago
|
||
So regression range contains "enable CSS grid": bug 1000592. Probably not a regression at all then?
But yeah it seems there's some exponential reflow going on here.
Comment 3•5 years ago
|
||
Bugbug thinks this bug is a regression, but please revert this change in case of error.
Comment 4•5 years ago
|
||
As per comment 2, not really a regression, but it does look like performance takes a nosedive with the nested display:grid
elements here; Mats, any thoughts on how to improve this?
Updated•5 years ago
|
Updated•5 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
Comment 6•4 years ago
|
||
Here's a case that likes to reproduce on firefox linux nightly, noting that it seems like the problem actually triggers after initial layout when I scroll the window.
Here's a profile that I gathered from the attached HTML file using "Firefox Platform" profiling settings AFTER the process hosting the file became unresponsive and hitting "capture" after what seemed like "long enough": https://share.firefox.dev/2V38Y2G
Edit: Note that the test file contains an external script reference to "simple.bundle.js" in the header that is moot and can be ignored. (I inlined the relevant parts of the script later in the file, along with the data that generates the dynamic HTML which isn't really all that complex.)
Assignee | ||
Comment 9•4 years ago
|
||
Daniel, can you please provide some optimizations that we could do for grids? Probably similar to the ones that we did for flexbox?
Comment 10•4 years ago
|
||
Yeah, bug 1524056 approximately covers adding some similar optimizations there. It's a substantial amount of work (mostly to reason about all the edge cases, the invariants that need to be maintained, etc); it's on the layout team's radar and is hopefully getting done sometime this year, but I'm not sure precisely when.
Comment 11•4 years ago
|
||
Specifically: CachedBAxisMeasurement and CachedFlexItemData are the two flexbox helper-structs that we may want to create some analogous versions of, over in our grid layout code. But it will take a good bit of investigation & reasoning about grid layout to determine what parts of these optimizations are sound, what sorts of conditions need to cause these cached values to be invalidated, etc.
Assignee | ||
Comment 12•3 years ago
|
||
I am starting to look into or learning CachedBAxisMeasurement and CachedFlexItemData, to see what we could do for grid. Just sort of mentions that I am looking into this bug.
Comment 13•3 years ago
|
||
Here's the reporter's testcase from comment 0, fwiw.
And here's a performance profile of me loading a local copy of this testcase in a fresh user-profile:
https://share.firefox.dev/3fdtoQa
Updated•3 years ago
|
Assignee | ||
Comment 14•3 years ago
|
||
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 15•3 years ago
|
||
Something like this should give us 64 bits to play with also on 32-bit systems...
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Comment 16•3 years ago
|
||
Depends on D115711
Updated•3 years ago
|
Updated•3 years ago
|
Comment 17•3 years ago
|
||
Comment 18•3 years ago
|
||
Backed out 2 changesets (Bug 1591366) for causing failures in table-grid-item-dynamic-004.html CLOSED TREE
Log: https://treeherder.mozilla.org/logviewer?job_id=351953476&repo=autoland&lineNumber=3892
Backout: https://hg.mozilla.org/integration/autoland/rev/36e353c3ca924fc8424ab2b4945e1af50df69c03
Comment 19•3 years ago
|
||
That's actually a test "unexpected-pass"! Interesting. Looks like that test is currently marked as expected-fail on all platforms, and started passing on Android with this patch, for some reason. This patch isn't really supposed to change behavior (aside from making us faster), so it shouldn't really be a thorough "fix" for any tests like that one.
That test's expected-failure is tracked in bug 1521088. Given that bug's relation to incremental reflow (e.g. from browser-window resizes), it's not entirely surprising that the test's behavior might change from a patch like this one that reduces the amount of redundant reflow that we're doing.
IMO, our simplest option for the moment is just to change the test annotation[1] to have an Android-specific [PASS, FAIL]
status (marking it as random on that platform, basically) -- assuming that the (occasional?) pass status is Android-specific.
Comment 20•3 years ago
|
||
Comment 21•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/0479e0a4cc15
https://hg.mozilla.org/mozilla-central/rev/19499821190d
Assignee | ||
Updated•3 years ago
|
Comment 22•3 years ago
|
||
Note: it seems that this did indeed fix things for attachment 9158023 [details] (asuth's persnosco testcase, "slow-grid.html bad things happen on scroll"). I can scroll that testcase in current Nightly with no noticeable rendering delays (whereas if I turn off the pref, I see extreme many-second delays and sometimes hangs).
However, the reporter's testcase that was quoted in comment 0 (which I attached as attachment 9221148 [details]) seems to still be pretty slow -- its render time has been cut in half (so it takes ~4 seconds instead of ~8 seconds, roughly; vs. it has no render delay in Chrome).
That testcase is approximately the same as the testcase in bug 1682686, so let's track that remaining slowness over there.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Description
•