Skip to content

Performance Issues in WASM Builds When Refocusing in Firefox #12126

@camblomquist

Description

@camblomquist

Bevy 0.13

Firefox (version unknown) tested on Windows 10 and MacOS 13

I had found that frame rate visibly decreases in Firefox, starting at a stable 60fps when first launching and decreasing all the way into the lower teens if the window is put out of focus then back into focus. When the window is put out of focus, the frame rate increases back to nearly reasonable levels. This does not appear to happen in Chrome, only Firefox. Safari has not yet been tested. Seems similar to #7242 but in that case, it was a Chromium browser and there's a lot of conflicting information in there without clear resolution or direction.

When the performance drops, the console repeatedly logs the following error (taken from the breakout example):

Uncaught Error: closure invoked recursively or after being dropped
    __wbindgen_throw https://bevy-webgl2-examples.pages.dev/Games/breakout/wasm_example.js:2035
    __wbg_adapter_51 https://bevy-webgl2-examples.pages.dev/Games/breakout/wasm_example.js:237
    real https://bevy-webgl2-examples.pages.dev/Games/breakout/wasm_example.js:210

I had thought this error popped up during input events but that does not appear to be the case as the error may be logged even without input.

A profile of the game shows long stretches of "Jank" and high levels of GC but other parts of the profile show most of the frame time being JS. I don't really know how to read the profile so I may just be misinterpreting it.
profile

Someone in the Discord recommended changing WinitSetting as a workaround

app
    .insert_resource(WinitSettings {
        focused_mode: UpdateMode::Continuous,
        unfocused_mode: UpdateMode::Continuous,
    })

I haven't had the opportunity to test this yet but if this does work, then it might be an issue with winit. I still felt it was worth documenting here for tracking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesO-WebSpecific to web (WASM) builds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions