Skip to content

Commit

Permalink
Merge branch 'main' into update-winit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Aug 31, 2023
2 parents 4f08176 + c2b85f9 commit e35ce43
Show file tree
Hide file tree
Showing 203 changed files with 5,611 additions and 3,213 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,25 @@ jobs:
with:
name: msrv
path: msrv/

check-bevy-internal-imports:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Check for bevy_internal imports
shell: bash
run: |
errors=""
for file in $(find examples tests -name '*.rs'); do
if grep -q "use bevy_internal" "$file"; then
errors+="ERROR: Detected 'use bevy_internal' in $file\n"
fi
done
if [ -n "$errors" ]; then
echo -e "$errors"
echo " Avoid importing bevy_internal, it should not be used directly"
echo " Fix the issue by replacing 'bevy_internal' with 'bevy'"
echo " Example: 'use bevy::sprite::MaterialMesh2dBundle;' instead of 'bevy_internal::sprite::MaterialMesh2dBundle;'"
exit 1
fi
7 changes: 6 additions & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
license = "MIT OR Apache-2.0"

[dev-dependencies]
glam = "0.24"
glam = "0.24.1"
rand = "0.8"
rand_chacha = "0.3"
criterion = { version = "0.3", features = ["html_reports"] }
Expand Down Expand Up @@ -47,6 +47,11 @@ name = "reflect_struct"
path = "benches/bevy_reflect/struct.rs"
harness = false

[[bench]]
name = "parse_reflect_path"
path = "benches/bevy_reflect/path.rs"
harness = false

[[bench]]
name = "iter"
path = "benches/bevy_tasks/iter.rs"
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/components/archetype_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct A<const N: u16>(f32);
fn setup(system_count: usize) -> (World, Schedule) {
let mut world = World::new();
fn empty() {}
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
for _ in 0..system_count {
schedule.add_systems(empty);
}
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/empty_archetypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn par_for_each(

fn setup(parallel: bool, setup: impl FnOnce(&mut Schedule)) -> (World, Schedule) {
let mut world = World::new();
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
if parallel {
world.insert_resource(ComputeTaskPool(TaskPool::default()));
}
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/scheduling/run_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn run_condition_yes(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(3));
fn empty() {}
for amount in 0..21 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems(empty.run_if(yes));
for _ in 0..amount {
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(yes));
Expand All @@ -41,7 +41,7 @@ pub fn run_condition_no(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(3));
fn empty() {}
for amount in 0..21 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems(empty.run_if(no));
for _ in 0..amount {
schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(no));
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) {
query.single().0
}
for amount in 0..21 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems(empty.run_if(yes_with_query));
for _ in 0..amount {
schedule.add_systems(
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) {
res.0
}
for amount in 0..21 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems(empty.run_if(yes_with_resource));
for _ in 0..amount {
schedule.add_systems(
Expand Down
8 changes: 4 additions & 4 deletions benches/benches/bevy_ecs/scheduling/running_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn empty_systems(criterion: &mut Criterion) {
group.measurement_time(std::time::Duration::from_secs(3));
fn empty() {}
for amount in 0..5 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
for _ in 0..amount {
schedule.add_systems(empty);
}
Expand All @@ -33,7 +33,7 @@ pub fn empty_systems(criterion: &mut Criterion) {
});
}
for amount in 1..21 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
for _ in 0..amount {
schedule.add_systems((empty, empty, empty, empty, empty));
}
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn busy_systems(criterion: &mut Criterion) {
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), D(0.0))));
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));
for system_amount in 0..5 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems((ab, cd, ce));
for _ in 0..system_amount {
schedule.add_systems((ab, cd, ce));
Expand Down Expand Up @@ -124,7 +124,7 @@ pub fn contrived(criterion: &mut Criterion) {
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0))));
world.spawn_batch((0..ENTITY_BUNCH).map(|_| (C(0.0), D(0.0))));
for system_amount in 0..5 {
let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems((s_0, s_1, s_2));
for _ in 0..system_amount {
schedule.add_systems((s_0, s_1, s_2));
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/scheduling/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn schedule(c: &mut Criterion) {

world.spawn_batch((0..10000).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0))));

let mut schedule = Schedule::new();
let mut schedule = Schedule::default();
schedule.add_systems((ab, cd, ce));
schedule.run(&mut world);

Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_math/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn easing(c: &mut Criterion) {
}

fn cubic_2d(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec2(0.0, 0.0),
vec2(0.0, 1.0),
vec2(1.0, 0.0),
Expand All @@ -27,7 +27,7 @@ fn cubic_2d(c: &mut Criterion) {
}

fn cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand All @@ -40,7 +40,7 @@ fn cubic(c: &mut Criterion) {
}

fn cubic_vec3(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
Expand All @@ -53,7 +53,7 @@ fn cubic_vec3(c: &mut Criterion) {
}

fn build_pos_cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand All @@ -66,7 +66,7 @@ fn build_pos_cubic(c: &mut Criterion) {
}

fn build_accel_cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand Down
94 changes: 94 additions & 0 deletions benches/benches/bevy_reflect/path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use std::{fmt::Write, str, time::Duration};

use bevy_reflect::ParsedPath;
use criterion::{
black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput,
};
use rand::{distributions::Uniform, Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;

criterion_group!(benches, parse_reflect_path);
criterion_main!(benches);

const WARM_UP_TIME: Duration = Duration::from_millis(500);
const MEASUREMENT_TIME: Duration = Duration::from_secs(2);
const SAMPLE_SIZE: usize = 500;
const NOISE_THRESHOLD: f64 = 0.03;
const SIZES: [usize; 6] = [100, 3160, 1000, 3_162, 10_000, 24_000];

fn deterministic_rand() -> ChaCha8Rng {
ChaCha8Rng::seed_from_u64(42)
}
fn random_ident(rng: &mut ChaCha8Rng, f: &mut dyn Write) {
let between = Uniform::try_from(b'a'..=b'z').unwrap();
let ident_size = rng.gen_range(1..128);
let ident: Vec<u8> = rng.sample_iter(between).take(ident_size).collect();
let ident = str::from_utf8(&ident).unwrap();
let _ = write!(f, "{ident}");
}

fn random_index(rng: &mut ChaCha8Rng, f: &mut dyn Write) {
let index = rng.gen_range(1..128);
let _ = write!(f, "{index}");
}

fn write_random_access(rng: &mut ChaCha8Rng, f: &mut dyn Write) {
match rng.gen_range(0..4) {
0 => {
// Access::Field
f.write_char('.').unwrap();
random_ident(rng, f);
}
1 => {
// Access::FieldIndex
f.write_char('#').unwrap();
random_index(rng, f);
}
2 => {
// Access::Index
f.write_char('[').unwrap();
random_index(rng, f);
f.write_char(']').unwrap();
}
3 => {
// Access::TupleIndex
f.write_char('.').unwrap();
random_index(rng, f);
}
_ => unreachable!(),
}
}

fn mk_paths(size: usize) -> impl FnMut() -> String {
let mut rng = deterministic_rand();
move || {
let mut ret = String::new();
(0..size).for_each(|_| write_random_access(&mut rng, &mut ret));
ret
}
}

fn parse_reflect_path(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("parse_reflect_path");
group.warm_up_time(WARM_UP_TIME);
group.measurement_time(MEASUREMENT_TIME);
group.sample_size(SAMPLE_SIZE);
group.noise_threshold(NOISE_THRESHOLD);
let group = &mut group;

for size in SIZES {
group.throughput(Throughput::Elements(size as u64));
group.bench_with_input(
BenchmarkId::new("parse_reflect_path", size),
&size,
|bencher, &size| {
let mut mk_paths = mk_paths(size);
bencher.iter_batched(
|| mk_paths(),
|path| assert!(ParsedPath::parse(black_box(&path)).is_ok()),
BatchSize::SmallInput,
);
},
);
}
}
Loading

0 comments on commit e35ce43

Please sign in to comment.