Closed Bug 1995614 Opened 1 year ago Closed 1 year ago

Lots of StringBuffer allocations during TodoMVC subtests

Categories

(Core :: DOM: HTML Parser, defect)

defect

Tracking

()

RESOLVED FIXED
147 Branch
Performance Impact low
Tracking Status
firefox147 --- fixed

People

(Reporter: denispal, Assigned: denispal)

References

(Blocks 1 open bug)

Details

(Keywords: perf-alert)

Attachments

(3 external files)

While investigating the inner html parsing performance during Speedometer3, I noticed we seem to allocate a lot of strings during tokenization. A lot of these allocations are for strings such as checkbox (30,000 times!), 0, 1 which are already static atoms. This occurs mostly during all of the TodoMVC subtests. Below is the list of most frequently allocated strings during parsing.

This seems to be most noticeable on Windows and Android where a lot of the time is spent in malloc locks during allocation.
Here is a profile on Windows: https://share.firefox.dev/4nalkQV

30385 [StringBuffer::Create] UTF-16: "checkbox" (len=8, bytes=16)
11528 [StringBuffer::Create] UTF-16: "2" (len=1, bytes=2)
9984 [StringBuffer::Create] UTF-16: "Smock_TaskList_18_N_svg__fill" (len=29, bytes=58)
9322 [StringBuffer::Create] UTF-16: "18" (len=2, bytes=4)
7702 [StringBuffer::Create] UTF-16: "5" (len=1, bytes=2)
6770 [StringBuffer::Create] UTF-16: "4" (len=1, bytes=2)
6739 [StringBuffer::Create] UTF-16: "1" (len=1, bytes=2)
6548 [StringBuffer::Create] UTF-16: "3" (len=1, bytes=2)
6247 [StringBuffer::Create] UTF-16: "0" (len=1, bytes=2)
5212 [StringBuffer::Create] UTF-16: "9" (len=1, bytes=2)
5010 [StringBuffer::Create] UTF-16: "0.25" (len=4, bytes=8)
4628 [StringBuffer::Create] UTF-16: "http://www.w3.org/2000/svg" (len=26, bytes=52)
4338 [StringBuffer::Create] UTF-16: "just-span spectrum-TreeView-itemLabel" (len=37, bytes=74)
4338 [StringBuffer::Create] UTF-16: "spectrum-TreeView-itemLink" (len=26, bytes=52)
2779 [StringBuffer::Create] UTF-16: "10" (len=2, bytes=4)
2496 [StringBuffer::Create] UTF-16: "M4.775 7.958a.5.5 0 0 1-.34-.133l-1.038-.958a.5.5 0 1 1 .678-.735l.656.606 2.14-2.52a.5.5 0 1 1 .762.65L5.156 7.785a.5.5 0 0 1-.35.175ZM4.775 12.959a.5.5 0 0 1-.34-.133l-1.038-.959a.5.5 0 0 1 .678-.735l.656.606 2.14-2.52a.5.5 0 1 1 .762.65l-2.477 2.916a.5.5 0 0 1-.35.176Z" (len=272, bytes=544)
2496 [StringBuffer::Create] UTF-16: "task-list-icon spectrum-Icon spectrum-TreeView-itemIndicator spectrum-TreeView-itemIcon spectrum-Icon--sizeM" (len=108, bytes=216)
2496 [StringBuffer::Create] UTF-16: "spectrum-TreeView-item nodetype-nonExpandableItem" (len=49, bytes=98)
2496 [StringBuffer::Create] UTF-16: "M1 1.5v14a.5.5 0 0 0 .5.5h15a.5.5 0 0 0 .5-.5v-14a.5.5 0 0 0-.5-.5h-15a.5.5 0 0 0-.5.5ZM16 15H2V2h14Z" (len=101, bytes=202)
2052 [StringBuffer::Create] UTF-16: "fill:#464646" (len=12, bytes=24)
1848 [StringBuffer::Create] UTF-16: "M12 9a.994.994 0 0 1-.292.705l-3.992 3.99a1 1 0 1 1-1.436-1.387l.025-.024L9.591 9 6.305 5.715A1 1 0 0 1 7.69 4.28l.025.025 3.991 3.99A.994.994 0 0 1 12 9Z" (len=154, bytes=308)
1848 [StringBuffer::Create] UTF-16: "spectrum-TreeView spectrum-TreeView--sizeS" (len=42, bytes=84)
1842 [StringBuffer::Create] UTF-16: "spectrum-Icon spectrum-TreeView-itemIndicator spectrum-TreeView-itemIcon" (len=72, bytes=144)
1644 [StringBuffer::Create] UTF-16: "spectrum-TreeView-item is-open nodetype-expandableItem" (len=54, bytes=108)
1326 [StringBuffer::Create] UTF-16: "30.577933450087567" (len=18, bytes=36)

I wrote a patch to atomize type attributes, and the strings "0" - "9". It seems to give around a 1% improvement on Windows and Android. This reduces the number of StringBuffer allocations from 1125294 to 503984 which is about a 55% reduction.

NI :hsivonen to take a look at this.

Severity: -- → S3
Flags: needinfo?(hsivonen)

Add static atoms for "2" -> "9", and do a fast path check for any single digit strings during tokenization and return the static atom directly. Also atomize type attributes during tokenization. This patch also cleans up some code in Element::SetAttr and nsHtml5TreeOperation so that it's easier to pass through an atom.

Attachment #9522106 - Attachment description: WIP: Bug 1995614: WIP: Atomize ATTR_TYPE strings and any single digit strings during tokenization. → Bug 1995614: Atomize ATTR_TYPE strings and any single digit strings during tokenization. r=hsivonen

Clearing needinfo to handle this via review.

(It's somewhat unfortunate that we need to have optimizations like this for synthetic tests that repeat the same thing more than in a real-world case. The existing special handling for class values was added for an earlier Speedometer.)

Flags: needinfo?(hsivonen)
Pushed by dpalmeiro@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/eee6488f783a https://hg.mozilla.org/integration/autoland/rev/6e6aca1969e0 Atomize ATTR_TYPE strings and any single digit strings during tokenization. r=hsivonen
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 146 Branch
Regressions: 1997489
Pushed by amarc@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/7d6cfb3a6f95 https://hg.mozilla.org/integration/autoland/rev/42c0e7efe0f2 Revert "Bug 1995614: Atomize ATTR_TYPE strings and any single digit strings during tokenization. r=hsivonen" for causing Bug 1997489 This reverts commit eee6488f783ab72b1afc95c0a824629b25e1458b.
Status: RESOLVED → REOPENED
Flags: needinfo?(dpalmeiro)
Resolution: FIXED → ---
Target Milestone: 146 Branch → ---
Pushed by dpalmeiro@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/430017d12e9a https://hg.mozilla.org/integration/autoland/rev/a0a4d1aa8331 Atomize ATTR_TYPE strings and any single digit strings during tokenization. r=hsivonen https://github.com/mozilla-firefox/firefox/commit/66b973dc4f5b https://hg.mozilla.org/integration/autoland/rev/0b7da8e951eb Use atoms for attributes if available instead of expecting a StringBuffer. r=hsivonen,media-playback-reviewers,firefox-svg-reviewers,karlt,dholbert https://github.com/mozilla-firefox/firefox/commit/c8a9b2340a5e https://hg.mozilla.org/integration/autoland/rev/a55e6a8352a8 Add a test to exercise single digit attribute strings across various element types. r=hsivonen
Regressions: 1999956
Status: REOPENED → RESOLVED
Closed: 1 year ago → 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 147 Branch

(In reply to Sandor Molnar[:smolnar] from comment #13)

https://hg.mozilla.org/mozilla-central/rev/a0a4d1aa8331
https://hg.mozilla.org/mozilla-central/rev/0b7da8e951eb
https://hg.mozilla.org/mozilla-central/rev/a55e6a8352a8

Perfherder has detected a browsertime performance change from push a55e6a8352a8395f09179cf38ab75a7ad69e1d25.

If you have any questions, please reach out to a performance sheriff. Alternatively, you can find help on Slack by joining #perf-help, and on Matrix you can find help by joining #perftest.

Improvements:

Ratio Test Platform Options Absolute values (old vs new) Performance Profiles
2% speedometer3 TodoMVC-JavaScript-ES6-Webpack-Complex-DOM/Adding100Items/Sync macosx1500-aarch64-shippable fission webrender 11.10 -> 10.87 Before/After
2% speedometer3 TodoMVC-JavaScript-ES6-Webpack-Complex-DOM/Adding100Items/total macosx1500-aarch64-shippable fission webrender 12.91 -> 12.65 Before/After

Details of the alert can be found in the alert summary, including links to graphs and comparisons for each of the affected tests.

If you need the profiling jobs you can trigger them yourself from treeherder job view or ask a performance sheriff to do that for you.

You can run all of these tests on try with ./mach try perf --alert 47488

The following documentation link provides more information about this command.

Keywords: perf-alert
Flags: needinfo?(dpalmeiro)
QA Whiteboard: [qa-triage-done-c148/b147]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: