Closed Bug 1853907 Opened 3 years ago Closed 2 years ago

Support allocating string characters in the nursery

Categories

(Core :: JavaScript: GC, task, P2)

task

Tracking

()

RESOLVED FIXED
122 Branch
Tracking Status
firefox122 --- fixed

People

(Reporter: jandem, Assigned: sfink)

References

(Blocks 3 open bugs)

Details

(Whiteboard: [sp3])

Attachments

(1 file, 6 external files, 3 obsolete files)

2.93 KB, text/plain
Details

I added some logging here for nursery-allocated strings with malloc-allocated characters.

Starting Firefox and running Speedometer 3, we allocated about 900,000 strings. Of these, more than 99.1% of strings have <= 256 bytes of characters allocated using malloc.

It would be nice if we could allocate those in the nursery instead, similar to what we do for slots and elements. It'd potentially get rid of the malloc, but also the registerMallocedBuffer call which also shows up in profiles.

Severity: -- → N/A
Priority: -- → P2
Blocks: 1803803
Depends on: 1859335
Assignee: nobody → sphink
Status: NEW → ASSIGNED
Attachment #9359683 - Attachment is obsolete: true
Pushed by sfink@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/47e60f2dcf3c Enable strings to have nursery-allocated chars. r=jonco https://hg.mozilla.org/integration/autoland/rev/92b2e95d20ee Copy nursery chars for AutoStableStringChars r=jonco https://hg.mozilla.org/integration/autoland/rev/cbff20e301c6 Add arena_id_t to nursery buffer allocation r=jonco https://hg.mozilla.org/integration/autoland/rev/6a1057bae45d Move responsibility of registering malloc buffers with the nursery to the callers, to prepare for situations where you can't predict whether the owner will be in the nursery or not. r=jonco https://hg.mozilla.org/integration/autoland/rev/244a4c91d231 Try to allocate nursery strings' data in the nursery r=jonco https://hg.mozilla.org/integration/autoland/rev/7067e9e6ee6c apply code formatting via Lando

There was a lando hiccup in landing this. It gave me an error message and the option to try again, I did, but then it showed that it had already successfully landed and the 2nd landing failed. So at least for now, it's all good.

A simple benchmark of allocating lots of 89-93 byte strings and immediately throwing away 99% of them gives

without patches:

$JS stringbench.js  13.74s user 1.02s system 177% cpu 8.337 total
$JS stringbench.js  12.69s user 1.04s system 175% cpu 7.820 total
$JS stringbench.js  12.69s user 0.86s system 176% cpu 7.674 total
$JS stringbench.js  13.46s user 1.07s system 176% cpu 8.218 total
$JS stringbench.js  13.53s user 1.04s system 178% cpu 8.184 total

with patches:

$JS stringbench.js  13.16s user 1.06s system 176% cpu 8.041 total
$JS stringbench.js  13.20s user 1.00s system 176% cpu 8.051 total
$JS stringbench.js  12.83s user 1.01s system 176% cpu 7.821 total
$JS stringbench.js  13.31s user 0.99s system 176% cpu 8.110 total
$JS stringbench.js  13.32s user 1.03s system 177% cpu 8.096 total

So the median goes from 8.184sec -> 8.051sec (1.6% faster), the mean 8.047 -> 8.024 (2.9% faster). Which is basically nothing, given that all this program is doing is allocating and freeing. In the browser, I suppose it might reduce jemalloc lock contention, but that's pure speculation.

Using much longer strings (1561-1565 bytes):

without patches:

$JS stringbench.js  25.83s user 1.14s system 195% cpu 13.798 total
$JS stringbench.js  25.35s user 1.13s system 195% cpu 13.523 total
$JS stringbench.js  25.46s user 1.06s system 195% cpu 13.598 total
$JS stringbench.js  26.65s user 1.15s system 195% cpu 14.222 total
$JS stringbench.js  24.83s user 1.11s system 195% cpu 13.287 total

with patches:

$JS stringbench.js  26.15s user 1.18s system 195% cpu 13.977 total
$JS stringbench.js  24.05s user 1.00s system 195% cpu 12.822 total
$JS stringbench.js  25.52s user 1.10s system 195% cpu 13.609 total
$JS stringbench.js  26.39s user 1.20s system 195% cpu 14.121 total
$JS stringbench.js  26.61s user 1.11s system 195% cpu 14.170 total

the median does 13.598 -> 13.977 so this is a net slowdown. Oh! But 1561 bytes is long enough that it won't be allocated in the nursery (there's a 1024 byte limit). Shortening those to about 975 bytes gives:

without patches:

$JS stringbench.js  18.78s user 1.26s system 178% cpu 11.257 total
$JS stringbench.js  18.37s user 1.17s system 178% cpu 10.977 total
$JS stringbench.js  17.09s user 1.21s system 175% cpu 10.407 total
$JS stringbench.js  17.36s user 1.20s system 177% cpu 10.465 total
$JS stringbench.js  18.54s user 1.29s system 176% cpu 11.216 total

with patches:

$JS stringbench.js  16.53s user 1.15s system 174% cpu 10.148 total
$JS stringbench.js  17.51s user 1.31s system 176% cpu 10.640 total
$JS stringbench.js  17.71s user 1.26s system 175% cpu 10.795 total
$JS stringbench.js  16.99s user 1.18s system 175% cpu 10.364 total
$JS stringbench.js  16.82s user 1.19s system 174% cpu 10.294 total

So that's 10.977 -> 10.364, a 5.6% speedup. That's finally showing some improvement. I'll attach the benchmark script.

Attached file stringbench.js —
Flags: needinfo?(sphink)
Pushed by sfink@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/59765c5886bd Enable strings to have nursery-allocated chars. r=jonco https://hg.mozilla.org/integration/autoland/rev/3f38854d14f6 Copy nursery chars for AutoStableStringChars r=jonco https://hg.mozilla.org/integration/autoland/rev/c1758b1e6239 Add arena_id_t to nursery buffer allocation r=jonco https://hg.mozilla.org/integration/autoland/rev/2b990cbcee93 Move responsibility of registering malloc buffers with the nursery to the callers, to prepare for situations where you can't predict whether the owner will be in the nursery or not. r=jonco https://hg.mozilla.org/integration/autoland/rev/e01b3b3267ad Try to allocate nursery strings' data in the nursery r=jonco https://hg.mozilla.org/integration/autoland/rev/9f5d6017e4f3 apply code formatting via Lando
Blocks: 1864086

Comment on attachment 9362940 [details]
Bug 1853907 - Add MarkInfo::UNKNOWN to the (debug-only) output possibilities (instead of falling back to NURSERY most of the time)

Revision D193260 was moved to bug 1864090. Setting attachment 9362940 [details] to obsolete.

Attachment #9362940 - Attachment is obsolete: true

Comment on attachment 9362941 [details]
Bug 1853907 - Fix tests whose behavior depends on nursery strings and string buffers

Revision D193261 was moved to bug 1864750. Setting attachment 9362941 [details] to obsolete.

Attachment #9362941 - Attachment is obsolete: true
Blocks: 1864750
Pushed by sfink@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/99b1db19b1ee Enable strings to have nursery-allocated chars. r=jonco https://hg.mozilla.org/integration/autoland/rev/3f10ccc211d6 Copy nursery chars for AutoStableStringChars r=jonco https://hg.mozilla.org/integration/autoland/rev/bd6ad1a1a257 Fix test whose behavior depends on nursery strings and string buffers r=jonco https://hg.mozilla.org/integration/autoland/rev/6e5d85fa4c3d Add arena_id_t to nursery buffer allocation r=jonco https://hg.mozilla.org/integration/autoland/rev/9047fbab5114 Move responsibility of registering malloc buffers with the nursery to the callers, to prepare for situations where you can't predict whether the owner will be in the nursery or not. r=jonco https://hg.mozilla.org/integration/autoland/rev/cb3c756775b2 Try to allocate nursery strings' data in the nursery r=jonco https://hg.mozilla.org/integration/autoland/rev/dbd1a6aef0a7 apply code formatting via Lando
Flags: needinfo?(sphink)

3.6% improvement on AWFY-Speedometer2.1-Flight-TodoMVC*

And maybe some smaller improvements on react-redux

Regressions: 1866607
Regressions: 1866817
No longer regressions: 1866998
Blocks: 1879918
Blocks: 1880044
Regressions: 1879918
No longer regressions: 1879918
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: