WebGL allocates new shared memory for each 100 kB of commands instead of reusing a command ring
Categories
(Core :: Graphics: CanvasWebGL, enhancement)
Tracking
()
People
(Reporter: pmenzel+bugzilla.mozilla.org, Unassigned)
References
(Blocks 1 open bug)
Details
Steps to reproduce
AI disclaimer: Drafted with claude-fable-5.2 and reviewed by me.
- Open https://webglsamples.org/aquarium/aquarium.html and set 15,000 or 30,000 fish (several uniform calls and one draw call per fish, more than 1 MB of serialized commands per frame).
- Profile the content process and the process that hosts
WebGLParent(perf, Linux x86-64, X11).
Actual results
WebGLChild::AllocPendingCmdBytes() allocates a new BigBuffer for each webgl.out-of-process.shmem-size (100 kB) of commands, WebGLChild::FlushPendingCmds() sends it with DispatchCommands, and WebGLParent drops it after running it. Per megabyte of commands that is ten rounds of creating, mapping and unmapping shared memory and 256 page faults on each side (about 36,000 page faults per second in the content process on this page). And as ClientWebGLContext::GetFrontBuffer() goes synchronous after more than ten flushes, the content process waits for the host at each frame instead of working on the next one.
Linux x86-64, X11, vsync off, PGO and cross-language LTO builds trained with the WebGL page of bug 2090025, WebGLSamples, mean of 4 runs, main (5a3f6397e615) against Chromium 156:
| Page | AMD Radeon Pro WX 5100, i7-7700, Mesa 26.2.4 | NVIDIA RTX 2080, i7-9700, 580.178.04 |
|---|---|---|
| Aquarium, 15,000 fish (fps) | 46.3 / 57.9 | 76.9 / 108.9 |
| Aquarium, 30,000 fish (fps) | 25.3 / 29.7 | 42.0 / 56.4 |
Expected results
The commands should go through shared memory that is set up once per context and reused, as in Chromium’s command buffer, and the content process should only wait if the host falls behind by whole frames.
With a patch that does this (one ring per context, each flush sends the byte range to run, so the order relative to all other PWebGL messages stays as it is; commands larger than half the ring keep their own buffer), the same builds reach, without → with the patch:
| Page | AMD WX 5100 | NVIDIA RTX 2080 |
|---|---|---|
| Aquarium, 15,000 fish (fps) | 46.3 → 51.2 (+11%) | 76.9 → 84.1 (+9%) |
| Aquarium, 30,000 fish (fps) | 25.3 → 27.8 (+10%) | 42.0 → 45.4 (+8%) |
| multiple-views (fps) | 1024 → 1123 (+10%) | 695 → 720 (+4%) |
| blob (fps) | 359 → 403 (+12%) | 587 → 664 (+13%) |
| dynamic-cubemap (fps) | 1041 → 1118 (+7%) | 955 → 972 (+2%) |
After that the thread of WebGLParent is the bottleneck (98% of a core, content process 77%): it runs both the WebGL validation and the driver. If the driver moves its work to a thread of its own, the transport
matters more, and Firefox passes Chromium on this page:
| Aquarium (fps) | Without → with the patch | Chromium 156 |
|---|---|---|
| AMD, Mesa glthread, 15,000 fish | 51.7 → 64.1 (+24%) | 57.9 |
| AMD, Mesa glthread, 30,000 fish | 27.2 → 32.8 (+20%) | 29.7 |
| NVIDIA, threaded optimizations, 15,000 fish | 90.1 → 104.2 (+16%) | 108.9 |
| NVIDIA, threaded optimizations, 30,000 fish | 49.7 → 59.3 (+19%) | 56.4 |
Notes on the last table:
- Mesa glthread:
gfxPlatformGtksetsmesa_glthread=falseon X11 with EGL (bug 1670545); these runs used an experimental build that leaves it alone. - NVIDIA threaded optimizations:
__GL_THREADED_OPTIMIZATIONS=1. - NVIDIA, 15,000 fish: one of the four runs with the patch gave 71 fps; three earlier runs gave 93.1 → 117.0.
macOS 14.8.1 (Mac mini 2018, i7-8700B, Intel UHD 630, ANGLE on Metal), main and the patch cross-built with cross-language LTO but without PGO, so the absolute numbers are lower than those of a release build; headless, mean of 3 runs:
| Page | Without → with the patch | Chrome 145 (headless) |
|---|---|---|
| Aquarium, 1,000 fish (fps) | 173.1 → 177.9 (+3%) | 285.7 |
| Aquarium, 5,000 fish (fps) | 71.0 → 74.6 (+5%) | 123.9 |
| Aquarium, 15,000 fish (fps) | 28.0 → 29.0 (+4%, within the spread) | 50.9 |
| multiple-views (fps) | 479.2 → 508.8 (+6%) | 588.2 (498 to 756) |
| blob (fps) | 270.7 → 282.0 (+4%) | 344.8 |
| dynamic-cubemap (fps) | 104.4 → 105.5 (+1%) | 135.0 |
Method: a local copy of WebGLSamples over HTTP, a fresh profile per run, 1920x1080 window, 8 s warm-up and 10 s measured, builds alternating (on macOS headless with the default 1366x768 window), layout.frame_rate=0 in Firefox and --disable-gpu-vsync --disable-frame-rate-limit in Chromium.
| Reporter | ||
Updated•17 days ago
|
Description
•