-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix infinite asset preparation due to undrained AssetEvent events #11383
Fix infinite asset preparation due to undrained AssetEvent events #11383
Conversation
this PR fixes #11240 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the render_to_texture
example on this PR and it is indeed fixed.
Also pointed my Bevy app which is broken on main towards this PR and that is fixed too 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: easier to review with whitespace diff hidden
|
||
impl<A: RenderAsset> FromWorld for CachedExtractRenderAssetSystemState<A> { | ||
fn from_world(world: &mut bevy_ecs::world::World) -> Self { | ||
Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: import World directly instead of writing out the full path
I was seeing significant memory usage increases (VRAM and CPU), as well as significantly longer load times when testing loading large scenes on main, and this fixes them. |
Merging now to help y'all diagnose other perf issues more easily. |
…vyengine#11383) # Objective After bevyengine#10520, I was experiencing seriously degraded performance that ended up being due to never-drained `AssetEvent` events causing havoc inside `extract_render_asset::<A>`. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project. * References bevyengine#10520 * Fixes bevyengine#11240 Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached `EventReader` behavior (which fixes it). ## Solution I followed the [`CachedSystemState` example](https://github.com/bevyengine/bevy/blob/3a666cab23eab5e83552ae074f47d8663221311e/crates/bevy_ecs/src/system/function_system.rs#L155) to make sure that the `EventReader` state is cached between frames like it used to be when it was an argument of `extract_render_asset::<A>`.
…vyengine#11383) # Objective After bevyengine#10520, I was experiencing seriously degraded performance that ended up being due to never-drained `AssetEvent` events causing havoc inside `extract_render_asset::<A>`. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project. * References bevyengine#10520 * Fixes bevyengine#11240 Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached `EventReader` behavior (which fixes it). ## Solution I followed the [`CachedSystemState` example](https://github.com/bevyengine/bevy/blob/3a666cab23eab5e83552ae074f47d8663221311e/crates/bevy_ecs/src/system/function_system.rs#L155) to make sure that the `EventReader` state is cached between frames like it used to be when it was an argument of `extract_render_asset::<A>`.
…vyengine#11383) # Objective After bevyengine#10520, I was experiencing seriously degraded performance that ended up being due to never-drained `AssetEvent` events causing havoc inside `extract_render_asset::<A>`. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project. * References bevyengine#10520 * Fixes bevyengine#11240 Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached `EventReader` behavior (which fixes it). ## Solution I followed the [`CachedSystemState` example](https://github.com/bevyengine/bevy/blob/3a666cab23eab5e83552ae074f47d8663221311e/crates/bevy_ecs/src/system/function_system.rs#L155) to make sure that the `EventReader` state is cached between frames like it used to be when it was an argument of `extract_render_asset::<A>`.
…vyengine#11383) # Objective After bevyengine#10520, I was experiencing seriously degraded performance that ended up being due to never-drained `AssetEvent` events causing havoc inside `extract_render_asset::<A>`. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project. * References bevyengine#10520 * Fixes bevyengine#11240 Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached `EventReader` behavior (which fixes it). ## Solution I followed the [`CachedSystemState` example](https://github.com/bevyengine/bevy/blob/3a666cab23eab5e83552ae074f47d8663221311e/crates/bevy_ecs/src/system/function_system.rs#L155) to make sure that the `EventReader` state is cached between frames like it used to be when it was an argument of `extract_render_asset::<A>`.
…vyengine#11383) # Objective After bevyengine#10520, I was experiencing seriously degraded performance that ended up being due to never-drained `AssetEvent` events causing havoc inside `extract_render_asset::<A>`. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project. * References bevyengine#10520 * Fixes bevyengine#11240 Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached `EventReader` behavior (which fixes it). ## Solution I followed the [`CachedSystemState` example](https://github.com/bevyengine/bevy/blob/3a666cab23eab5e83552ae074f47d8663221311e/crates/bevy_ecs/src/system/function_system.rs#L155) to make sure that the `EventReader` state is cached between frames like it used to be when it was an argument of `extract_render_asset::<A>`.
Objective
After #10520, I was experiencing seriously degraded performance that ended up being due to never-drained
AssetEvent
events causing havoc insideextract_render_asset::<A>
. The same events being read over and over again meant the same assets were being prepared every frame for eternity. For what it's worth, I was noticing this on a static scene about every 3rd or so time running my project.Why these events aren't sometimes drained between frames is beyond me and perhaps worthy of another investigation, but the approach in this PR effectively restores the original cached
EventReader
behavior (which fixes it).Solution
I followed the
CachedSystemState
example to make sure that theEventReader
state is cached between frames like it used to be when it was an argument ofextract_render_asset::<A>
.