-
I'm coding a bezier curve editor and following an official example. But I'm having performance problems and isolated the part that seems to be running very poorly: use bevy::{
app::{App, Startup, Update},
core_pipeline::core_3d::Camera3dBundle,
ecs::{
component::Component,
system::{Commands, Query},
},
gizmos::gizmos::Gizmos,
math::{
cubic_splines::{CubicBezier, CubicCurve, CubicGenerator},
vec3, Vec3,
},
prelude::default,
render::color::Color,
transform::components::Transform,
DefaultPlugins,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, draw_curves)
.run();
}
#[derive(Component)]
pub struct Curve(CubicCurve<Vec3>);
fn setup(mut commands: Commands) {
let points = [[
vec3(-6., 2., 0.),
vec3(12., 8., 0.),
vec3(-12., 8., 0.),
vec3(6., 2., 0.),
]];
let bezier = CubicBezier::new(points).to_curve();
commands.spawn(Curve(bezier));
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(0., 6., 12.).looking_at(Vec3::new(0., 3., 0.), Vec3::Y),
..default()
},));
}
fn draw_curves(query: Query<&Curve>, mut gizmos: Gizmos) {
for cubic_curves in &query {
gizmos.linestrip(cubic_curves.0.iter_positions(32), Color::WHITE);
}
} I'm running with I did some tests, like changing the number of segments, and even with just one segment it runs poorly. As the print shows: Is there anything I can do to improve it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 18 replies
-
Have you tried profiling this? Maybe there's something surprising there. See https://github.com/bevyengine/bevy/blob/main/docs/profiling.md to get started. Are there similar perf problems just drawing the same number of points with gizmos? |
Beta Was this translation helpful? Give feedback.
I tried changing version, going back to bevy 0.12.1 works perfectly, CPU usage does not exceed 30%. But just switching to 0.13, the problem comes back. And using v0.14.0-rc.2 just gives the crash that I posted.
Forcing GL as backend gives: