Allocate AttrArray storage from a main-thread-only jemalloc arena
Categories
(Core :: DOM: Core & HTML, task)
Tracking
()
| 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.
| Assignee | ||
Comment 1•15 days ago
|
||
A main-thread-only arena takes no lock, which saves a lock and unlock on
every allocation and free of an attribute array.
Updated•15 days ago
|
Comment 3•11 days ago
|
||
| bugherder | ||
Updated•1 day ago
|
Description
•