Closed Bug 1844464 Opened 2 years ago Closed 2 years ago

Optimize gfxHarfBuzzShaper::ShapeText if possible, for Editor-TipTap

Categories

(Core :: Layout: Text and Fonts, task)

task

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: mstange, Assigned: jfkthame)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(3 files, 1 obsolete file)

On Windows, 20% of the time on the Speedometer 3 subtest "Editor-TipTap" is spent inside the function gfxHarfBuzzShaper::ShapeText. Reducing the time in this function would have an appreciable impact on the score of that subtest.

Profile: https://share.firefox.dev/3pZqFD9 (double-click a function to view line-by-line timings)

https://shell--speedometer-preview.netlify.app/?suite=Editor-TipTap&iterationCount=100

I should note that we are already faster than Chrome at layout on this subtest, but this may not remain so indefinitely, and a percent is a percent.

A couple of things catch my eye in this profile that may be worth exploring:

First, gfxDWriteFont::GetGlyphWidth currently uses an nsTHashMap to cache glyph widths for the font; we could switch this to mozilla::HashTable, which should be faster, and/or we could experiment with layering a fast MRUCache in front of the hashtable.

We could also try an MRUCache to accelerate gfxHarfBuzzShaper::GetNominalGlyph.

The other thing that stands out is gfxFontShaper::MergeFontFeatures, which again is heavy on hashtable work. We could use mozilla::HashTable for a faster implementation, but I think a better way will be to use a simple sorted array to accumulate the features. No real-world content is likely to have so many separate features specified that we really need the hashtable.

I'll experiment with some patches along these lines.

Assignee: nobody → jfkthame

With the patches above, the Editor-TipTap score in my local (non-PGO) build rises from 6.806 to 7.252, which seems a healthy win.

Very nice!

We need to do this in order to add internal caches to the shaper
(without a lot of thread-safety pain).

Attachment #9344836 - Attachment description: Bug 1844464 - patch 2 - Add a MruCache to accelerate gfxHarfBuzzShaper::GetNominalGlyph. r=#gfx-reviewers → Bug 1844464 - patch 2 - Add an MruCache to accelerate gfxHarfBuzzShaper::GetNominalGlyph. r=#gfx-reviewers
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/52e713717c12 patch 0 - Require the gfxFont lock to be held while calling the shaper. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/fc05f1740cda patch 1 - Optimize gfxFontShaper::MergeFontFeatures by using a sorted array rather than nsTHashMap to accumulate the features. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/1fa1a2e110e5 patch 2 - Add an MruCache to accelerate gfxHarfBuzzShaper::GetNominalGlyph. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/6921e3bf21b2 patch 3 - Add an MruCache in front of the shaper's call to gfxFont::GetGlyphWidth(). r=gfx-reviewers,lsalzman
Blocks: 1844830
No longer blocks: 1844830
Attachment #9344860 - Attachment is obsolete: true

Revised patches to avoid the need to hold the gfxFont lock, which was leading to possible-deadlock warnings.

Flags: needinfo?(jfkthame)
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/12d609f24c16 patch 1 - Optimize gfxFontShaper::MergeFontFeatures by using a sorted array rather than nsTHashMap to accumulate the features. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/a0c8264fc96a patch 2 - Add an MruCache to accelerate gfxHarfBuzzShaper::GetNominalGlyph. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/4a7e5d260b93 patch 3 - Add an MruCache in front of the shaper's call to gfxFont::GetGlyphWidth(). r=gfx-reviewers,lsalzman
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: