Closed
Description
Bevy version
Main branch commit: d8974e7c3d84189313268f475ceeff9393cedffa
Operating system & version
Windows 10 Vulkan and DX12 API.
What you did
The example code is small and easy to understand:
use bevy::{prelude::*, diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}};
#[derive(Component)]
pub struct Nothing;
#[derive(Bundle)]
pub struct NoBundle {
nothing: Nothing,
}
fn startup(
mut commands: Commands,
) {
let mut entities = Vec::new();
for _ in 0..5000000 {
entities.push(NoBundle {
nothing: Nothing,
});
}
commands.spawn_batch(entities);
}
fn main() {
App::new()
.insert_resource(WindowDescriptor {
width: 1270.0,
height: 720.0,
title: String::from("Bug"),
..Default::default()
})
.insert_resource(ClearColor(Color::rgb(0.211, 0.643, 0.949)))
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugins(DefaultPlugins)
.add_startup_system(startup)
.run();
}
What you expected to happen
Creating large amounts of entities shouldn't decrease rendering performance unless they are actually drawing something to the screen.
What actually happened
Performance decreases rapidly with increased entity counts. On higher end machines this is less noticeable, but still becomes an issue.
Additional information
The decrease in performance can be traced to this:
bevy/crates/bevy_render/src/lib.rs
Lines 193 to 202 in 458cb7a
Reserving entity ID's for every entity seems to be costly when dealing with a large number of entities.
Possible solutions:
- Don't reserve entities that don't render anything. I'm not sure how performant that will be overall?
- Possibly this could be mitigated by using a sub world where you could store extremely large numbers of entities without the rendering world being aware of said entities.