Fix infinite asset preparation due to undrained AssetEvent events #11383
Merged
alice-i-cecile merged 1 commit intobevyengine:mainfrom Jan 27, 2024
Merged
Conversation
Member
|
this PR fixes #11240 |
torsteingrindvik
approved these changes
Jan 19, 2024
Contributor
torsteingrindvik
left a comment
There was a problem hiding this comment.
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 👍
atlv24
approved these changes
Jan 22, 2024
Contributor
atlv24
left a comment
There was a problem hiding this comment.
note: easier to review with whitespace diff hidden
JMS55
approved these changes
Jan 26, 2024
|
|
||
| impl<A: RenderAsset> FromWorld for CachedExtractRenderAssetSystemState<A> { | ||
| fn from_world(world: &mut bevy_ecs::world::World) -> Self { | ||
| Self { |
Contributor
There was a problem hiding this comment.
Small nit: import World directly instead of writing out the full path
Contributor
|
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. |
Member
|
Merging now to help y'all diagnose other perf issues more easily. |
This was referenced Jan 27, 2024
tjamaan
pushed a commit
to tjamaan/bevy
that referenced
this pull request
Feb 6, 2024
…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>`.
maximetinu
pushed a commit
to Sophya/bevy
that referenced
this pull request
Feb 12, 2024
…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>`.
maximetinu
pushed a commit
to Sophya/bevy
that referenced
this pull request
Feb 12, 2024
…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>`.
maximetinu
pushed a commit
to Sophya/bevy
that referenced
this pull request
Feb 12, 2024
…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>`.
maximetinu
pushed a commit
to Sophya/bevy
that referenced
this pull request
Feb 12, 2024
…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>`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
After #10520, I was experiencing seriously degraded performance that ended up being due to never-drained
AssetEventevents 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
EventReaderbehavior (which fixes it).Solution
I followed the
CachedSystemStateexample to make sure that theEventReaderstate is cached between frames like it used to be when it was an argument ofextract_render_asset::<A>.