Closed Bug 1484938 Opened 6 years ago Closed 6 years ago

Implementing Append() via Replace() leads to cache-unfriendly access pattern

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla64
Tracking Status
firefox64 --- fixed

People

(Reporter: hsivonen, Assigned: hsivonen)

References

Details

Attachments

(1 file)

Currently, Append() (and AppendASCII(), AppendLiteral(), etc.) are this wrappers around Replace() (and ReplaceASCII(), ReplaceLiteral(), etc.) with a zero-length cut that starts at the end of the string.

While this leads to the correct observable result, it is done with writes ordered in a cache-unfriendly way: The zero terminator is written first and then the newly-appended data is written between the old end of the string and the zero terminator.

Implementing Append() (etc.) directly in terms of StartBulkWriteImpl() (or special-casing zero-length cut at the end of the string in Replace() to use StartBulkWriteImpl() directly and not via MutatePrep()) would result in a linear write pattern, which should be more cache-friendly.

(I expect the difference to be small enough not to be easily quantifiable but to add up still.)
(In reply to Henri Sivonen (:hsivonen) from comment #0)
> MutatePrep()

s/MutatePrep/ReplacePrep/
Assignee: nobody → hsivonen
Status: NEW → ASSIGNED
Try run:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=a8111dfc75c09d3b1adcb0162de0cd6c6c25a8fd

(The riskiest part is removing the "-1 means 'use strlen()'" behavior.)
(In reply to Henri Sivonen (:hsivonen) from comment #3)
> (The riskiest part is removing the "-1 means 'use strlen()'" behavior.)

Removing that behavior is futile.

Another try run:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=74dec051de3a2d5c1ca39bfc24c52da098d77743
Cross-platform crash around layout/style/test/test_value_cloning.html on try. :-(
(In reply to Henri Sivonen (:hsivonen) from comment #11)
> Cross-platform crash around layout/style/test/test_value_cloning.html on
> try. :-(

On closer look, it seems it's a timeout and the crash comes from the harness forcibly stopping the browser.

Let's see if the timeout goes away by rebasing, i.e. if I had an unlucky base revision:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=b4de43504dcd4a93551735f77d742c05b3157e3f
(In reply to Henri Sivonen (:hsivonen) from comment #12)
> Let's see if the timeout goes away by rebasing

It doesn't.
The timeout is due to bad interaction of bug 1486711 and NS_UnescapeURL.

The test case uses exceptionally large percent-escaped data: URLs. NS_UnescapeURL first calls SetCapacity() with a large capacity and then calls single-char Append() very often. This results in a huge amount of time getting spent in memset() poisoning the buffer from after the current length to the capacity.

Probably the number of bytes to poison should be capped. Also, NS_UnescapeURL should probably use lower-level writing than using single-char Append() often.
(In reply to Henri Sivonen (:hsivonen) from comment #15)
> With fix for bug 1490973:
> https://treeherder.mozilla.org/#/
> jobs?repo=try&revision=176c1ab6a64dd5a3917f1624b71f213b58f02801

Still times out. :-(
Depends on: 1490972
Comment on attachment 9005982 [details]
Bug 1484938 - Make XPCOM string appends and copying assignments write the terminator after writing content.

Nathan Froyd [:froydnj] has approved the revision.
Attachment #9005982 - Flags: review+
Pushed by hsivonen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/00df8305ed36
Make XPCOM string appends and copying assignments write the terminator after writing content. r=froydnj
https://hg.mozilla.org/mozilla-central/rev/00df8305ed36
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: