Skip to content

Commit

Permalink
Add inline(never) to bench systems (#9824)
Browse files Browse the repository at this point in the history
# Objective

It is difficult to inspect the generated assembly of benchmark systems
using a tool such as `cargo-asm`

## Solution

Mark the related functions as `#[inline(never)]`. This way, you can pass
the module name as argument to `cargo-asm` to get the generated assembly
for the given function.

It may have as side effect to make benchmarks a bit more predictable and
useful too. As it prevents inlining where in bevy no inlining could
possibly take place.

### Measurements

Following the recommendations in
<https://easyperf.net/blog/2019/08/02/Perf-measurement-environment-on-Linux>,
I

1. Put my CPU in "AMD ECO" mode, which surprisingly is the equivalent of
disabling turboboost, giving more consistent performances
2. Disabled all hyperthreading cores using `echo 0 >
/sys/devices/system/cpu/cpu{11,12…}/online`
3. Set the scaling governor to `performance`
4. Manually disabled AMD boost with `echo 0 >
/sys/devices/system/cpu/cpufreq/boost`
5. Set the nice level of the criterion benchmark using `cargo bench … &
sudo renice -n -5 -p $! ; fg`
6. Not running any other program than the benchmarks (outside of system
daemons and the X11 server)

With this setup, running multiple times the same benchmarks on `main`
gives me a lot of "regression" and "improvement" messages, which is
absurd given that no code changed.

On this branch, there is still some spurious performance change
detection, but they are much less frequent.

This only accounts for `iter_simple` and `iter_frag` benchmarks of
course.
  • Loading branch information
nicopap authored Oct 2, 2023
1 parent 8cc255c commit 47409c8
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_frag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut data in self.1.iter_mut(&mut self.0) {
data.0 *= 2.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_frag_foreach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 *= 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 *= 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 .0 *= 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut data| {
data.0 .0 *= 2.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_frag_sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut data in self.1.iter_mut(&mut self.0) {
data.0 *= 2.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_frag_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut data in self.1.iter_mut(&mut self.0) {
data.0 .0 *= 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut data in self.1.iter_mut(&mut self.0) {
data.0 .0 *= 2.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for (velocity, mut position) in self.1.iter_mut(&mut self.0) {
position.0 += velocity.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_simple_foreach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1
.for_each_mut(&mut self.0, |(velocity, mut position)| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1
.for_each_mut(&mut self.0, |(velocity, mut position)| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut item| {
item.1 .0 += item.0 .0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
self.1.for_each_mut(&mut self.0, |mut item| {
item.1 .0 += item.0 .0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for (velocity, mut position) in self.1.iter_mut(&mut self.0) {
position.0 += velocity.0;
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_simple_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Benchmark {
Self(world, Box::new(system))
}

#[inline(never)]
pub fn run(&mut self) {
self.1.run((), &mut self.0);
}
Expand Down
1 change: 1 addition & 0 deletions benches/benches/bevy_ecs/iteration/iter_simple_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut item in self.1.iter_mut(&mut self.0) {
item.1 .0 += item.0 .0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<'w> Benchmark<'w> {
Self(world, query)
}

#[inline(never)]
pub fn run(&mut self) {
for mut item in self.1.iter_mut(&mut self.0) {
item.1 .0 += item.0 .0;
Expand Down

0 comments on commit 47409c8

Please sign in to comment.