Open Bug 1902867 Opened 2 years ago Updated 18 days ago

WebGL aquarium - Firefox much slower than Chromium/Edge

Categories

(Core :: Graphics: CanvasWebGL, defect)

Desktop
All
defect

Tracking

()

People

(Reporter: 08xjcec48, Unassigned)

References

(Depends on 2 open bugs)

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0

Steps to reproduce:

Actual results:

Edge: 60 fps
Firefox: 33 fps

Both browsers have uBlock Origin with the same selection of lists.

https://share.firefox.dev/3xkZSFa

Component: Untriaged → Graphics: CanvasWebGL
OS: Unspecified → Windows 10
Product: Firefox → Core
Hardware: Unspecified → Desktop
See Also: → 1653777
See Also: → 1902819
Attached file about-support.txt —
See Also: 1902819 →
Attachment #9407968 - Attachment mime type: text/plain → application/json

Looking at the profile, I think the way we do WebGL remoting (content processes sending IPC messages to the GPU process) is probably responsible for all of the difference in observed performance here, whereas chromium-based browsers run the OpenGL ES calls in the content processes (i.e. every content process is a GPU process), we do it remotely to avoid giving the content processes access to the GPU (a security/performance tradeoff).

Severity: -- → S3

I'm seeing even larger difference with 30,000 fish using 5700x/6700XT:
Edge: 80 fps
Nightly: 29 fps
Nightly with Angle disabled: 44 fps

Version: Firefox 127 → Trunk
OS: Windows 10 → All
Summary: WebGL aquarium - Firefox much slower than Edge (Ryzen 7 5700u) → WebGL aquarium - Firefox much slower than Chromium/Edge
Status: UNCONFIRMED → NEW
Ever confirmed: true

Here are profiles from Bas:
Chrome
Firefox

They suggest to me our WebGL serialization is a lot more expensive than Chrome's is.

Two thing that stand out:

  1. We spending a lot of time shared_ptr incRef/decRef (presumably because it's atomic)
  2. We spending a bunch of time zero filling on demand: KiPageFault. Presumably, because we're allocating a bunch of fresh buffers every frame.
Depends on: 1976241
Depends on: 1976319

Just an update from my test last year after 1976241 which was reported to increase fps by ~20%.

Now I'm seeing with same config:
Edge: 20 fps (-60 fps regression)
Nightly: 33 fps (+4 fps, though it was ~32 before 1976241)
Nightly with Angle disabled: 45 fps (+1 fps, though it regressed to ~43 from other changes)

I've updated to an RX 9070 XT and Angle finally got an update after years.
The Angle update unfortunately resulted in a regression:
Before: 31 fps
After: 26 fps
Angle Disabled: 46 fps

As this is easy to reproduce, it’d be great if you could bisect the regression with mozregression.

For the record, on a Dell Precision 3620 with Intel i7-7700, and AMD graphics

01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon Pro WX 5100] [1002:67c7]

self-built Firefox 159.0.1 shows around 40 fps with 15,000 fish, and self-built Chromium 156.0.8078.79 around 58.4 fps. Downloaded Firefox Nightly gives 37.8 fps. Let’s see if claude-opus-5.5 finds something with the prompt below.

On maleficent with amdgpu, running https://webglsamples.org/aquarium/aquarium.html Firefox 159.0.1 has around 40 fps with 15,000 fishes, but /pkg/chromium-156.0.8078.79-0/ shows almost 50 fps. Please improve Firefox. Feel free to download latest nightly and do it with that. Tell me how I can allow you as root to get a “real” session.

AI disclaimer: Analyzed and drafted by claude-opus-5.5 and reviewed by me.

Profiling results on the same machine (Dell Precision 3620): Linux X11, XFCE, AMD Radeon Pro WX 5100 with radeonsi and Mesa 26.2.4, i7-7700. Test: aquarium with 15,000 fish in a 1920×1080 window, 3–4 alternating runs per variant, standard deviation under 1 fps.

Variant fps
Chromium 156 58.0
Nightly 161 37.9
local opt build of main 38.3
+ webgl.out-of-process.shmem-size = 1000000 41.7
+ Mesa glthread allowed on X11/EGL 44.5
+ uniform setters serialized without the generic path 45.4

Findings:

  1. A synchronous GetFrontBuffer round trip every frame. This page writes about 3 MB of commands per frame. With the default 100 KB buffers that is more than 10 flushes per frame, so ClientWebGLContext::GetFrontBuffer (tooManyFlushes) falls back to the synchronous path. With 1 MB buffers, present stays asynchronous: +9%. Bug 1665289 last tuned this default in 2020.
  2. No glthread on X11/EGL. gfxPlatformGtk::InitMesaThreading sets mesa_glthread=false there since bug 1670545. Chromium’s GPU process uses glthread on this machine. Allowing it moves the driver work off CanvasRenderer (host thread from 94–100% down to about 60%) and gives +6%. It didn't crash here, but the original crash in bug 1670545 was about DRI3 thread safety, so this needs care, for example limiting glthread to WebGL’s offscreen contexts.
  3. Host-side per-call cost isn’t the limit any more. Making WebGLContext::IsContextLost cheaper, for example, measured 0%.
  4. The content main thread now sets the frame rate. It is 100% busy, measured with perf. About 31% is the page’s JIT code and about 12% sin/cos. Typed-array handling in the bindings takes about 9% (JS::PinArrayBufferOrViewLength, GetCurrentData). About 8% is kernel time for page faults, roughly 36,000 per second, from writing into a fresh shared-memory buffer after every flush. That is the "fresh buffers every frame" from bug 1902867 comment 5. Reusing the buffers would need the parent to hand them back.

For comparison, Chromium’s renderer main thread is also at 100%, but finishes a frame in about 17 ms against about 22 ms for Firefox. Its JIT code takes about 3.4 ms per frame.

The patches for items 2 and 4 are local experiments, not submitted yet.

Gecko profiles (1 ms interval; threads GeckoMain, Compositor, Renderer, CanvasRenderer and IPC; about 30 s including page load, steady state after about 15 s): Nightly 161 with default settings, and the local build with all three changes and 1 MB buffers. In the first, the content main thread spends about 7% in the synchronous PWebGL::Msg_GetFrontBuffer during paint. In the second, CanvasRenderer has headroom and the content main thread is the only saturated thread.

(In reply to Paul Menzel from comment #8)

As this is easy to reproduce, it’d be great if you could bisect the regression with mozregression.

If you mean from before this issue was created then I don't really have time for that right now. If you meant the regression I reported (31->26 fps) then that was from updating Angle after years of no updates in bug 1908744.
The odd part is if I override the Angle dlls from an old Edge build from before they stopped shipping them (ver 2.1.46450.0) then I get 35 fps, which is still far from disabling Angle's performance but significant increase over master.

If you meant the regression I reported (31->26 fps) then that was from updating Angle after years of no updates in bug 1908744.

Yes, this is what I meant. Sorry for missing this.

Depends on: 2091491
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: