Closed Bug 1931789 Opened 9 months ago Closed 6 months ago

avoid quadratic case when appending style sheets

Categories

(Core :: CSS Parsing and Computation, defect)

defect

Tracking

()

RESOLVED FIXED
137 Branch
Tracking Status
firefox137 --- fixed

People

(Reporter: tnikkel, Assigned: tnikkel)

References

(Blocks 1 open bug)

Details

(Keywords: perf-alert, Whiteboard: [sp3])

Attachments

(2 files)

No description provided.

size_t is the return type of nsTArray::IndexOf. NoIndex is defined as (size_t)-1. Implicitly converting this to int32_t which is signed and might be a different bit width seems sketchy to me. This makes this clear and explicit.

FillStyleSetDocumentSheets specifically iterates the existing sheets in reverse order when calling AddDocStyleSheet in order to avoid this problem (because FindDocStyleSheetInsertionPoint iterates from the start of existing sheets).

FindDocStyleSheetInsertionPoint has to deal with some other types of sheets, so just flipping the order it iterates seems a bit more complex.

The slow case that we want to avoid here is the other caller of AddDocStyleSheet: AddStyleSheetToStyleSets. When the sheets are appended at the end one by one using this function we hit the quadratic worst case.

This is about 0.75% of the full sp3 suite.

Whiteboard: [sp3]
Duplicate of this bug: 1945382

I had a totally busted wip that I plan to clean up and land.

Flags: needinfo?(emilio)

It was of course a silly off-by-one.

Attachment #9438225 - Attachment description: Bug 1931789. Avoid quadratic behaviour of FindDocStyleSheetInsertionPoint in the common append case. r?smaug,#dom-core,#style → Bug 1931789 - Avoid quadratic behaviour of FindDocStyleSheetInsertionPoint in the common append case. r?smaug,#dom-core,#style

I wonder, was 0.75% covering also the time outside the time which sp3 runner uses for the results?

(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #9)

I wonder, was 0.75% covering also the time outside the time which sp3 runner uses for the results?

Yes. We figured out that was the case on matrix, I never updated this bug with that information. (Which is why I haven't had time to come back to fix the review comments here.)

This has come up in other places tho, so would be nice to fix regardless

Oh sure, I wasn't saying this isn't good :) This stuff does indeed show up in the profiles when not filtering out the not-measured parts of sp3.

Yeah, still worth it to do, just not as important as if it were on some critical paths for common interactive web operations.

Duplicate of this bug: 1840656
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a1695c424bbd Change DocumentOrShadowRoot::StyleOrderIndexOfSheet to return size_t. r=emilio https://hg.mozilla.org/integration/autoland/rev/8a1c41b85d1c Avoid quadratic behaviour of FindDocStyleSheetInsertionPoint in the common append case. r=smaug
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/923fc29a2667 Fix an assert triggering in some devtools tests.
Status: NEW → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 137 Branch
See Also: → 1950631
See Also: → 1951042

(In reply to Norisz Fay [:noriszfay] from comment #17)

https://hg.mozilla.org/mozilla-central/rev/a1695c424bbd
https://hg.mozilla.org/mozilla-central/rev/8a1c41b85d1c
https://hg.mozilla.org/mozilla-central/rev/923fc29a2667

Perfherder has detected a browsertime performance change from push 8a1c41b85d1ce6a77c2abc7c0df2af5ea4f3557a.

Improvements:

Ratio Test Platform Options Absolute values (old vs new) Performance Profiles
8% speedometer3 cpuTime macosx1400-64-shippable-qr fission webrender 48,010.34 -> 43,978.17 Before/After
3% speedometer3 TodoMVC-Lit-Complex-DOM/DeletingAllItems/Async macosx1400-64-shippable-qr fission webrender 1.87 -> 1.82 Before/After

Details of the alert can be found in the alert summary, including links to graphs and comparisons for each of the affected tests.

If you need the profiling jobs you can trigger them yourself from treeherder job view or ask a sheriff to do that for you.

You can run these tests on try with ./mach try perf --alert 44206

For more information on performance sheriffing please see our FAQ.

Keywords: perf-alert
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: