Closed Bug 1848765 Opened 1 years ago Closed 11 months ago

nsDisplayList::Sort should use nsTArray::StableSort

Categories

(Core :: Web Painting, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 --- fixed

People

(Reporter: smaug, Assigned: jstutte)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file)

Currently the method uses std::stable_sort on top of nsTArray
https://searchfox.org/mozilla-central/rev/ce049e593c7d062a039938cabccaab4c14b8ebfd/layout/painting/nsDisplayList.h#3197
That triggers ElementAt calls which do bound checks.
nsTArray::StableSort would avoid that.

https://bugzilla.mozilla.org/show_bug.cgi?id=1668200 has a similar fix for some animation code.

The ElementAt calls do show up in the profiles

Component: Layout → Web Painting

FWIW, nsTArray<>::StableSort is based on std::stable_sort since bug 1147091.

But: nsTArray<>::StableSort uses Elements() to make it operate on the plain C/C++ array, which should avoid ElementsAt. Note that std::stable_sort may always need an additional (fallible) allocation to reach O(n*log(n)).

See Also: → 1887697
Assignee: nobody → jstutte
Status: NEW → ASSIGNED
Pushed by jstutte@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cee7118d2c81 Use nsTArray<>::StableSort for nsDisplayList::Sort. r=smaug
Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 126 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: