bevyengine / bevyengine/bevy

Rapidly growing number of WebGPU objects causing stuttering.

Open
#22,545 6 comments 3 reactions 0 assignees View on GitHub
A-Rendering C-Bug S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features

- 0.18.0 (also on 0.17.3)
- webgpu

## \[Optional\] Relevant system information

```ignore
AdapterInfo { name: "", vendor: 0, device: 0, device_type: Other, driver: "", driver_info: "", backend: BrowserWebGpu }
```

I'm running an AMD Ryzen™ AI Max+ 395 on Windows 11. I recorded similar behavior in firefox as well as chrome, though it seems to be more periodic and frequent on chrome.

## What you did

When building for the web, I have noticed significant periodic stuttering in my game and have been tracking it down. Eventually tracked the stutter to garbage collection.

## What went wrong

with this minimal setup:

main.rs:
```
use bevy::{
prelude::*,
window::{Window, WindowPlugin},
};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
// fill the entire browser window
fit_canvas_to_parent: true,
// don't hijack keyboard shortcuts like F5, F6, F12, Ctrl+R etc.
prevent_default_event_handling: false,
..default()
}),
..default()
}))
.add_systems(Startup, startup)
.run();
}

fn startup(mut commands: Commands) {
commands.spawn(Camera3d::default());
}
```

Cargo.toml:
```
[package]
name = "bevy_stability_test"
version = "0.1.0"
edition = "2024"

[dependencies]
bevy = { version = "0.18.0", features = [
"webgpu",
] }
wasm-bindgen = "0.2.108"

[profile.release]
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
# strip = false
strip = "debuginfo"
```

.cargo/config.toml:
```
[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"

[build]
target = "wasm32-unknown-unknown"
```

running:
```
cargo run
```
(or with --release and wasm-opt)

There is a steady growth of gpu objects with are later destroyed causing a lag spike.
(I captured this with https://chromewebstore.google.com/detail/webgpu-inspector/holcbbnljhkpkjkhgkagjkhhpeochfal?hl=en-US)

Image

There also seems to be a relationship with cpu memory growth and cleanup aswell (through that might just be memory referencing the gpu objects?)

Image

If I disable the camera spawning this does not happen though! So it has to be something stemming from the camera I believe.

Please try to reproduce this on your own machine as I cant be sure this is not just how my setup behaves.

Resolving this issue would make the web experience of bevy apps be far far better!

Contributor guide

Open the contributing guide

Research direction

Start with the minimal main.rs and its startup system, then reproduce the wasm32-unknown-unknown build using the shown Cargo.toml and .cargo/config.toml with the webgpu feature enabled. Compare runs with and without Camera3d::default() and inspect GPU object and memory growth with the WebGPU Inspector. Done means identifying and resolving the camera-triggered growth so the periodic stuttering no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
game-dev, performance, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.