bevy
bevy copied to clipboard
Fix infinite asset preparation due to undrained AssetEvent events
Objective
After #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 #10520
- Fixes #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 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 PR fixes https://github.com/bevyengine/bevy/issues/11240
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.