Closed Bug 1352531 Opened 8 years ago Closed 8 years ago

can mozilla::dom::FontFaceSet::FindOrCreateUserFontEntryFromFontFace be faster?

Categories

(Core :: DOM: CSS Object Model, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Performance Impact high
Tracking Status
firefox55 --- fixed

People

(Reporter: dbaron, Assigned: heycam)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

Attachments

(3 files)

In the profile in bug 1329601 comment 13 I noticed that we're spending a substantial amount of time in mozilla::dom::FontFaceSet::FindOrCreateUserFontEntryFromFontFace, most of which is spent in memory allocation and freeing. Could this be made any faster? Here's a slice of the profile focusing on this: https://perfht.ml/2oqedI5
Flags: needinfo?(jfkthame)
That seems to indicate that it's Block objects inside gfxSparseBitSet / gfxCharacterMap, which is for compact unicode-range value storage. There might be ways of improving gfxSparseBitSet, but if are recreating the gfxCharacterMap object for the same FontFace often, we could just cache its value on the FontFace, and update or invalidate it when the descriptors on the FontFace are changed.
Attached patch WIP v0.1Splinter Review
Does this help?
Attachment #8853617 - Flags: feedback?(dbaron)
Comment on attachment 8853617 [details] [diff] [review] WIP v0.1 It's hard for me to tell if it helps; I was actually looking at a profile that Ehsan took, and I haven't even gotten the profiler working on my primary machine. Maybe Ehsan can tell, though?
Attachment #8853617 - Flags: feedback?(dbaron) → feedback?(ehsan)
Whiteboard: [qf:?] → [qf]
Whiteboard: [qf] → [qf:p1]
Ehsan, could you try this patch, or give me some instructions so I can see if it helps whatever workload you were profiling? Thanks!
Flags: needinfo?(jfkthame) → needinfo?(ehsan)
FWIW this profile came from the test case linked to in bug 1269695 comment 10. The STR is in the bug. I'm doing a build to test.
This is a profile from a build before your changes: https://perfht.ml/2pENdoI We spend 24ms in FindOrCreateUserFontEntryFromFontFace. This is a profile from a build after your changes: https://perfht.ml/2oXxLGx The function doesn't show up in the profile any more! So your patch helps make the function much faster, and if there is no downsides with it we should land it, but it doesn't improve anything in the grand scheme of things...
Flags: needinfo?(ehsan)
Comment on attachment 8853617 [details] [diff] [review] WIP v0.1 BTW super sorry for the long delay here.
Attachment #8853617 - Flags: feedback?(ehsan) → feedback+
(In reply to :Ehsan Akhgari (super long backlog, slow to respond) from comment #7) > So your patch helps make the function much faster, and if there is no > downsides with it we should land it, but it doesn't improve anything in the > grand scheme of things... Sorry, I think this came out negatively but I didn't mean it that way! I meant to say that this test case is really really slow. But of course it's not this function's fault. :-)
(In reply to :Ehsan Akhgari (super long backlog, slow to respond) from comment #9) > Sorry, I think this came out negatively but I didn't mean it that way! I > meant to say that this test case is really really slow. But of course it's > not this function's fault. :-) No worries, thanks for testing. :-) Since the patch doesn't need any more work, may as well get it landed.
Attached patch patchSplinter Review
This is the same as the WIP patch.
Assignee: nobody → cam
Status: NEW → ASSIGNED
Attachment #8859860 - Flags: review?(dbaron)
Comment on attachment 8859860 [details] [diff] [review] patch >+ // FIXME(heycam): If we are changing unicode-range, then a FontFace object >+ // representing this rule must have its mUnicodeRange value invalidated. Do you need to fix this? (This is a regression from this bug, right, in that you don't have any code to set mUnicodeRangeDirty to true other than the constructor?)
Flags: needinfo?(cam)
I guess that comment is misplaced, since nsCSSFontFace::SetDesc is only called from nsCSSParser when parsing the rule initially. nsCSSFontFaceStyleDecl::SetProperty is where we should be noting that we need to handle dynamic updates. But we do support modifying unicode-range through FontFace::SetUnicodeRange, and we correctly flush the font set in that case. So I need to set mUnicodeRangeDirty there.
Flags: needinfo?(cam)
Comment on attachment 8859860 [details] [diff] [review] patch OK, cancelling review until comment 13 is done.
Attachment #8859860 - Flags: review?(dbaron)
(Oh, I made the change but forgot to upload the patch. Needinfo to remind myself to upload it when I'm back at the computer the patch is on...)
Flags: needinfo?(cam)
Flags: needinfo?(cam)
Comment on attachment 8860911 [details] Bug 1352531 - Make dom::FontFace cache its gfxCharacterMap instead of rebuilding it every time. https://reviewboard.mozilla.org/r/131944/#review139368
Attachment #8860911 - Flags: review?(dbaron) → review+
Pushed by cmccormack@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3c4e4f95b499 Make dom::FontFace cache its gfxCharacterMap instead of rebuilding it every time. r=dbaron
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Performance Impact: --- → P1
Whiteboard: [qf:p1]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: