Closed Bug 1726570 Opened 4 years ago Closed 4 years 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: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 93 Branch

Jonathan, is there a specific reason you made the GeneratedFile use force=True?

Flags: needinfo?(jfkthame)

(In reply to Mike Hommey [:glandium] from comment #5)

Jonathan, is there a specific reason you made the GeneratedFile use force=True?

I'm not sure at this point, sorry; I have a vague recollection of encountering some kind of build failure while working on this, so maybe that was a fix/workaround for that? If you think it's redundant and everything builds OK without, I'd be fine with dropping it.

Flags: needinfo?(jfkthame)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: