Closed
Bug 1503928
Opened 6 years ago
Closed 6 years ago
FontFamilyList::Contains does some slow string comparisons
Categories
(Core :: Layout: Text and Fonts, enhancement)
Core
Layout: Text and Fonts
Tracking
()
RESOLVED
FIXED
mozilla65
Tracking | Status | |
---|---|---|
firefox65 | --- | fixed |
People
(Reporter: smaug, Assigned: jfkthame)
Details
Attachments
(1 file)
1.39 KB,
patch
|
lsalzman
:
review+
|
Details | Diff | Splinter Review |
https://perf-html.io/public/00cd9c8c3184cbc571e0b3a744477635a5905508/calltree/?file=profile_raptor-tp6-amazon-firefox%2Fraptor-tp6-amazon-firefox_pagecycle_1.profile&globalTrackOrder=0-1-2-3-4&hiddenGlobalTracks=1-2-4&invertCallstack&localTrackOrderByPid=3625-1-0~3748-0~3870-0~&range=1.9671_4.5774~4.0345_4.1193&search=ToLowercase&thread=4&v=3 nsAtomString is slow, could we use nsDependentAtomString somehow. And LowerCaseEqualsLiteral I don't know why the raptor profile shows this stuff so badly. Does Amazon really load so many fonts, or is this about comparing to local font names or what?
Assignee | ||
Comment 1•6 years ago
|
||
AFAICS we can't use LowerCaseEqualsLiteral here, because neither of the strings concerned is a literal; and we can't use nsDependentAtomString because we're going to apply ToLowerCase to the string, so we need our own copy. One micro-optimization we could do here would be to use nsAutoString for listname, to avoid a separate string allocation. An alternative approach would be to use nsCaseInsensitiveStringComparator instead of applying ToLowerCase to the strings. (And then we could indeed use nsDependentAtomString.) Do you happen to know whether that's likely to be more or less performant than pre-lowercasing the strings, given that we're likely to be doing a series of comparisons against the same input string?
Reporter | ||
Comment 2•6 years ago
|
||
If we can avoid allocating string from atom, I would definitely expect it to be faster. Allocations are very slow.
Assignee | ||
Comment 3•6 years ago
|
||
OK, I instrumented a local (opt) build, and confirmed that (a) using a local nsAutoString is better than nsAtomString (as expected), because it avoids the extra allocation; and (b) better still is to use nsDependentAtomString and nsCaseInsensitiveStringComparator instead of lowercasing the two strings. Average duration of calls to Contains() in a brief test across a few sites went from 0.75µs (original) to 0.58µs (using nsAutoString) to 0.51µs (avoiding string copies and use case-insensitive comparator).
Assignee | ||
Updated•6 years ago
|
Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Assignee | ||
Updated•6 years ago
|
Attachment #9022169 -
Flags: review?(lsalzman)
Updated•6 years ago
|
Attachment #9022169 -
Flags: review?(lsalzman) → review+
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/72b791de2f09 Optimize FontFamilyList::Contains to avoid allocation and string-copying. r=lsalzman
Comment 5•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/72b791de2f09
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
status-firefox65:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla65
You need to log in
before you can comment on or make changes to this bug.
Description
•