Closed Bug 1823270 Opened 2 years ago Closed 2 years ago

gfxTextRun::SortGlyphRuns may be inefficient

Categories

(Core :: Graphics: Text, defect)

defect

Tracking

()

RESOLVED FIXED
113 Branch
Tracking Status
firefox113 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

References

Details

Attachments

(1 file)

In some cases, gfxTextRun::SortGlyphRuns ends up finding numerous GlyphRun records that can be coalesced with their neighbors; but the use of nsTArray::RemoveElementAt(index) to remove the redundant ones individually becomes inefficient if the array is large, and multiple removals are needed, as each operation will move all the following elements.

We have nsTArray::RemoveElementsBy(predicate) to do this more efficiently as a single pass over the array, so we should adapt SortGlyphRuns to use this.

In the patches for bug 1823215, we eliminated the use of a local copy of the glyph runs array
during SortGlyphRuns; but we call RemoveElementAt individually for each run to be coalesced,
which means potentially moving all the rest of the array multiple times. Instrumentation shows
that we sometimes end up with dozens of glyphruns to be coalesced (or even hundreds/thousands,
in pathological cases), which becomes quite inefficient.

Using RemoveElementsBy(predicate) instead will minimize the copying/moving of the remaining
array elements.

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Attachment #9323824 - Attachment description: Bug 1823270 - Rewrite gfxTextRun::SortGlyphRuns to use RemoveElementsByinstead of RemoveElementAt when merging adjacent runs, to minimize array-data shifting. r=#gfx-reviewers → Bug 1823270 - Rewrite gfxTextRun::SortGlyphRuns to use RemoveElementsBy instead of RemoveElementAt when merging adjacent runs, to minimize array-data shifting. r=#gfx-reviewers
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/48b90cfc92d5 Rewrite gfxTextRun::SortGlyphRuns to use RemoveElementsBy instead of RemoveElementAt when merging adjacent runs, to minimize array-data shifting. r=gfx-reviewers,lsalzman
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch
Blocks: 1823644
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: