Closed Bug 1978645 Opened 4 months ago Closed 1 month ago

Consider using BufferAllocator for OOL data for wasm GC objects

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
145 Branch
Tracking Status
firefox145 --- fixed

People

(Reporter: rhunt, Assigned: jonco)

References

(Blocks 3 open bugs)

Details

Attachments

(4 files)

The GC now has support for a BufferAllocator [1] which can be used to allocate variable sized extra data and associate it with a GC object. This looks like it could replace our use of the Malloc'edBlockCache [2]. We should see how well it performs if we were to switch.

[1] https://searchfox.org/mozilla-central/rev/387160feb07b75ae76bfc12df035a10f58d25168/js/src/gc/BufferAllocator.h#195
[2] https://searchfox.org/mozilla-central/rev/387160feb07b75ae76bfc12df035a10f58d25168/js/src/gc/MallocedBlockCache.h#19

Blocks: 1983485
Depends on: 1989977
Assignee: nobody → jcoppeard

I ran some benchmarks on these patches in the shell, testing on x64 Linux and arm64 macOS. This used nightly builds where the poisoning behaviour is the same for both jemalloc and the buffer allocator.

                           Linux                  macOS
                           Score  Major  Minor    Score  Major  Minor
                                  time   time            time   time

  Dart-flute-complex-wasm  +5.5%  -13%   -18%     +6.6%  -8.4%  -28%     
  Dart-flute-todomvc-wasm  +3.1%  +5%    -28%     +3.7%  +50%   -32%
  Kotlin-compose-wasm      +3.2%  -      -2.8%    -1%    +6.6%  -12%         

I did some profiling on a browser build (macOS) to check nothing untoward was happening. These show a significant reduction in main thread minor GC time due to not sweeping trailer blocks there and reduction in helper thread time calling object finalizers, with a smaller increase in helper thread time for buffer allocator sweeping.

I don't know why Dart-flute-todomvc-wasm shows increased major GC time in the shell. This didn't happen in browser testing.

I had to limit the maximum buffer size to allocate directly in the nursery because j2cl-box2d-wasm was filling the nursery with these leading to longer nursery collections which lead to reducing the nursery size to compensate. Updated results with this change:

                           macOS             Linux
                           Score   Total GC  Score   Total GC   
                                   time              time   

  Dart-flute-complex-wasm  +6.7%   -24%      +5.3%   -17%
  Dart-flute-todomvc-wasm  +3.1%   -24%      +3.3%   -22%
  Kotlin-compose-wasm      +3.1%   -5.8%     +4.4%   -5.6%
  j2cl-box2d-wasm          -       -12%      -       -18%

Wasm GC allocations tend to get tenured more often than regular JS objects
which means minor GCs can spend a lot of time moving these directly allocated
buffers. This increases minor GC time which also means we keep the nursery size
smaller, affecting performance. This adds an option to set the maximum size of
buffer allocations made directly in the nursery. For Wasm GC allocations we'll
make this smaller than the regular size.

Attachment #9514958 - Attachment description: WIP: Bug 1978645 - Part 1: Use buffer allocator for wasm struct outline data → Bug 1978645 - Part 1: Use buffer allocator for wasm struct outline data r?jseward
Attachment #9514959 - Attachment description: WIP: Bug 1978645 - Part 2: Use buffer allocator for wasm array data → Bug 1978645 - Part 2: Use buffer allocator for wasm array data r?jseward
Attachment #9514960 - Attachment description: WIP: Bug 1978645 - Part 3: Remove malloc block cache and nursery trailer tracking → Bug 1978645 - Part 3: Remove malloc block cache and nursery trailer tracking r?jseward
Regressions: 1993004
QA Whiteboard: [qa-triage-done-c146/b145]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: