Closed Bug 1726570 Opened 4 months ago Closed 3 months ago

Accelerate nsFind by caching the IsCombiningDiacritic result for each Unicode codepoint

Categories

(Core :: Find Backend, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
93 Branch
Tracking Status
firefox93 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

Details

Attachments

(1 file)

Following on from bug 1725555 comment 5, the last profile there shows that looking up mozilla::unicode::IsCombiningDiacritic for each character as we search is a significant cost. This function currently does an ICU property lookup.

We can significantly speed this up by caching the exact result we care about (based on several comparisons of the CombiningClass property value) in a gfxSparseBitSet, which compactly records a single boolean flag for each codepoint, and doesn't waste space on the large areas of the code space where there are no true entries.

Comparing profiles of searching the log file mentioned in bug 1725555 for the text "Task Finished" in a local opt build, it currently takes around 830-850ms for nsFind::Find to search the entire document:
https://share.firefox.dev/3Db9jFg

With a patch to cache the IsCombiningDiacritic value, this is reduced to around 570-610ms:
https://share.firefox.dev/3j1KSSI

The gfxSparseBitSet that is needed to cache this flag for the whole Unicode range only takes around 3Kbytes, so the footprint is negligible. There's some one-time cost to initializing it, which is around 10ms on my machine (though obviously it'll be more on slower systems).

No user-visible change to behavior, except that searching a huge document
becomes slightly quicker.

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Severity: -- → N/A
Component: Find Toolbar → Find Backend
Product: Toolkit → Core
Attachment #9237046 - Attachment description: Bug 1726570 - Accelerate nsFind by caching the IsCombiningDiacritic result for each Unicode codepoint. r=emilio → Bug 1726570 - Accelerate nsFind by precomputing a const SharedBitSet for IsCombiningDiacritic. r=emilio
Pushed by jkew@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a93cff68de74
Accelerate nsFind by precomputing a const SharedBitSet for IsCombiningDiacritic. r=emilio
Pushed by smolnar@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/2fd9e81cee3c
Fix lint failures. a-lint-fix. CLOSED TREE
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 93 Branch
You need to log in before you can comment on or make changes to this bug.