bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.73k stars 3.61k forks source link

25MB/s memory leak on Windows 10 with empty app #11922

Closed Inspirateur closed 9 months ago

Inspirateur commented 9 months ago

Relevant information

Bevy 0.12.1

2024-02-17T12:08:05.337670Z  INFO bevy_winit::system: Creating new window "OurCraft" (0v0)
2024-02-17T12:08:05.661033Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce GTX 1060 3GB", vendor: 4318, device: 7170, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "536.99", backend: Vulkan }
2024-02-17T12:08:06.340935Z  INFO system{name="bevy_diagnostic::system_information_diagnostics_plugin::internal::log_system_info"}: bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz", core_count: "6", memory: "31.9 GiB" }

What you did

I was experiencing a huge memory leak, initially 200MB/s, on my bevy game https://github.com/Inspirateur/ourcraft even when seemingly nothing was happening (no entity changes, no new terrain generating) that quickly lead to a crash when RAM ran out (status access violation).

Here are the debugging steps I took then:

  1. profiling with Tracy with memory feature enabled, surprisingly the leak seemed to disappear when recording with tracy (super annoying)
  2. Looked if I had Vulkan validation layers/SDK installed (seemed like a plausible cause): i don't have it installed
  3. Put Window config back to default (I read Window could be the cause of some memory leaks): reduced the leak to 25MB/s !
  4. remove everything from app except DefaultPlugins: did not change the leak (proving it doesn't come from my code)
  5. Switched wgpu backend from vulkan to dx12: did not change the leak

This issue seems similar to https://github.com/bevyengine/bevy/issues/5691 but my leak is bigger, persists with cargo run --release and always end up crashing the game (and sometimes bricking my computer too) !

Another reproduction

My friend tried the game out and had the same leak (same rate too) with this config:

2024-02-17T13:17:54.964283Z  INFO bevy_winit::system: Creating new window "OurCraft" (0v0)
2024-02-17T13:17:55.317590Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3060 Ti", vendor: 4318, device: 9353, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "537.34", backend: Vulkan }
2024-02-17T13:17:55.815319Z  INFO system{name="bevy_diagnostic::system_information_diagnostics_plugin::internal::log_system_info"}: bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 10 Pro", kernel: "19045", cpu: "Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz", core_count: "4", memory: "15.9 GiB" }
443eb9 commented 9 months ago

Check this message.

Inspirateur commented 9 months ago

Check this message.

Wow i honestly didn't believe this could cause a leak so big but I removed it from my cargo.toml and the leak is gone ! Thank you very much 👍

That being said this really ought to be documented as it has cost me (and probably others) numerous hours of debugging !

ghost commented 9 months ago

This is due to tracing-tracy being enabled, not a bug.