Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy memory usage grows over time #5691

Open
Byteron opened this issue Aug 14, 2022 · 11 comments
Open

bevy memory usage grows over time #5691

Byteron opened this issue Aug 14, 2022 · 11 comments
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-UI Graphical user interfaces, styles, layouts, and widgets C-Docs An addition or correction to our documentation C-Performance A change motivated by improving speed, memory usage or compile times

Comments

@Byteron
Copy link
Contributor

Byteron commented Aug 14, 2022

Bevy version

0.8

What went wrong

I left a bevy app running in the background for a long time, and well, it grew to 12 GB memory usage over the course of ~8 hours.
The App is just a few planes and a simple controller system.

image

It seems that a bevy app just with the default plugins and nothing else also grows over time, so it's not my code but a bevy problem.

@Byteron Byteron added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Aug 14, 2022
@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times A-Diagnostics Logging, crash handling, error reporting and performance analysis and removed S-Needs-Triage This issue needs to be labelled labels Aug 14, 2022
@alice-i-cecile
Copy link
Member

This has been examined before; IIRC this is the result of logging enabled during debug builds.

@Byteron
Copy link
Contributor Author

Byteron commented Aug 15, 2022

I can confirm that this is only happening in debug builds. when cargo run --release the mem usage is not growing.

@afonsolage
Copy link
Contributor

afonsolage commented Aug 15, 2022

I let a game with only Default plugins running for some time, with cargo run --release on Windows 11 and it is still increasing memory usage.

use bevy::prelude::*;

fn main() {
    App::new().add_plugins(DefaultPlugins).run();
}

image
On startup

image
1 hour later

image
3 hours later

image
7 hours later

Running Time Memory Usage
0h 65.9 MB
1h 150.6 MB
3h 436.3 MB
7h 73.9 MB

Edit: It seems this is some internal memory/cache pool. I noticed when it was about to reach 500 MB it dropped to ~50 MB again and restarted the cycle.

So I don't think there is a memory leak.

@alice-i-cecile
Copy link
Member

Moving this to a docs issue then :)

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation A-UI Graphical user interfaces, styles, layouts, and widgets and removed C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times labels Aug 15, 2022
@bjorn3
Copy link
Contributor

bjorn3 commented Aug 15, 2022

It seems this is some internal memory/cache pool. It noticed when it was about to reach 500 MB it dropped to ~50 MB again and restarted the cycle.

Does it also drop down in case of memory pressure from other program? If so, that should be fine, if confusing for end users. If not, it is probably still an issue.

@afonsolage
Copy link
Contributor

afonsolage commented Aug 15, 2022

It seems this is some internal memory/cache pool. It noticed when it was about to reach 500 MB it dropped to ~50 MB again and restarted the cycle.

Does it also drop down in case of memory pressure from other program? If so, that should be fine, if confusing for end users. If not, it is probably still an issue.

image

It was using around 800MB and then I launched 15 wasm bevymark with 500k sprites each to force Chrome do what it does better: eating ram. Then reflect_example, which is the program that is running for about 12hs, dropped it's memory to about 100MB.

After a while it crashed, since the Windows ran out of ram:

memory allocation of 9591008 bytes failed
error: process didn't exit successfully: `target\release\reflect_example.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)

@hammypants
Copy link

This has been examined before; IIRC this is the result of logging enabled during debug builds.

Is there a way to disable this?

fn main() {
    App::default().add_plugins_with(DefaultPlugins, |group| { group.disable::<bevy::log::LogPlugin>() }).run();
}

Still grows at an exceptional rate with cargo run.

@alice-i-cecile
Copy link
Member

Yep, we're getting another memory leak over in #6417: the logging is a factor, but far from the only issue.

@james7132
Copy link
Member

#6878 seems to fix the issue seen in #6417. @Byteron can you check if it fixes this leak?

@alice-i-cecile alice-i-cecile added the C-Performance A change motivated by improving speed, memory usage or compile times label Dec 10, 2022
@ghost ghost mentioned this issue Jan 6, 2023
@Yairama
Copy link

Yairama commented Apr 30, 2023

Maybe this will help someone, that's why I'm commenting.

When I installed Vulkan, I started to get a Validation layers error, an error that does not stop the execution but causes a slight increase in memory over time.
The error was:

ERROR wgpu_hal::vulkan::instance: VALIDATION [UNASSIGNED-CoreValidation-Shader-InconsistentSpirv (0x6bbb14)] Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x24ebcd349f0, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: [VUID-StandaloneSpirv-OpTypeRuntimeArray-04680] Vulkan, OpTypeStruct containing an OpTypeRuntimeArray must be decorated with Block or BufferBlock. %PointLights = OpTypeStruct %_runtimearr_PointLight

It was solved by removing vulkan completely.

@TotalKrill
Copy link
Contributor

On webbrowsers this results in crashed tabs after the app has been running for a while. However, we seem to be able to work around this by using:

DefaultPlugins.build()
         .disable::<LogPlugin>()
         .disable::<DiagnosticsPlugin>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-UI Graphical user interfaces, styles, layouts, and widgets C-Docs An addition or correction to our documentation C-Performance A change motivated by improving speed, memory usage or compile times
Projects
None yet
Development

No branches or pull requests

8 participants