Closed Bug 2092625 Opened 15 days ago Closed 11 days ago

Allocate AttrArray storage from a main-thread-only jemalloc arena

Categories

(Core :: DOM: Core & HTML, task)

task

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: jjaschke, Assigned: jjaschke)

References

(Blocks 1 open bug)

Details

Attachments

(1 external file)

AttrArray::Impl is allocated with plain malloc/realloc. On the main thread that goes to the main thread's thread-local mozjemalloc arena, which is created without flags and therefore takes its lock (an uncontended atomic compare-exchange, plus the release on unlock) on every allocation and free. DOMArena avoids this with ARENA_FLAG_THREAD_MAIN_THREAD_ONLY, which selects the lock-free path in mozjemalloc.

Attribute arrays belong to nodes, which are created and destroyed on the main thread (Stylo worker threads only read them), so they can come from a main-thread-only arena too. Only the initial allocation needs to name the arena: realloc and free find the arena a pointer belongs to, so the rest of AttrArray stays unchanged.

In Speedometer 3 profiles, mozjemalloc lock and unlock are a few percent of main-thread time, spread over many allocation sites (bug 1928177 tracks the general fix). Attribute arrays are one of the hotter sites during innerHTML and DOM construction. On a local innerHTML micro-benchmark this measured about -1.2% for fragments taking the fast path and -0.6% for ones going through the full parser.

A main-thread-only arena takes no lock, which saves a lock and unlock on
every allocation and free of an attribute array.

Assignee: nobody → jjaschke
Status: NEW → ASSIGNED
Pushed by jjaschke@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/34d470167dba https://hg.mozilla.org/integration/autoland/rev/23135ddbf9d6 Allocate attribute arrays from a main-thread-only arena. r=dom-core-reviewers,smaug
Status: ASSIGNED → RESOLVED
Closed: 11 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
QA Whiteboard: [qa-triage-done-c163/b162]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: