Skip to content

Conversation

@BD103
Copy link
Member

@BD103 BD103 commented Dec 26, 2024

Objective

Solution

  • Create the bench! macro, which generates the name of the benchmark at compile time.

    Migrating is a single line change, and it will automatically update if you move the benchmark to a different module:

    + use benches::bench;
    
    fn my_benchmark(c: &mut Criterion) {
    -   c.bench_function("my_benchmark", |b| {});
    +   c.bench_function(bench!("my_benchmark"), |b| {});
    }
  • Migrate all reflection benchmarks to use bench!.

  • Fix a few places where black_box() or Criterion is misused.

Testing

cd benches

# Will take a long time!
cargo bench --bench reflect

# List out the names of all reflection benchmarks, to ensure I didn't miss anything.
cargo bench --bench reflect -- --list

# Check for linter warnings.
cargo clippy --bench reflect

# Run each benchmark once.
cargo test --bench reflect

BD103 added 13 commits December 26, 2024 09:50
- Added `black_box()` to places where random arguments should be simulated. See <https://doc.rust-lang.org/nightly/std/hint/fn.black_box.html#how-to-use-this> for more on this.
- Moved cloning benchmarks to be above overloading benchmarks.
- Renamed `overload()`'s `add()` to `simple()` to complement `complex()`.
- Split `overload()` into `with_overload()` and `call_overload()`.
- Switched `std` import to `core`.
    - Benchmarks will likely never be `#![no_std]`, but it's best to be consistent with the rest of the project.
Now benchmarks in this module can call `create_group()` instead of manually setting the warm-up and measurement time. I also set the plot scale to be logarithmic, since it looks better with our current sizes.
I also repeat what I did in e69f75e here by defining a `create_group()` function that sets common benchmark configuration.
That should be 316, not 3160 🤦

I do wonder how long that's been there, though! :)
- Use `BenchmarkId::from_parameter()` instead of repeating the benchmark name.
- Change it so we only assert that the parse is successful during tests, not the actual benchmark.
Also extract the `create_group()` function.
There's definitely quite a few misconceptions about this function, and they can only be disproven by Compiler Explorer / Godolt. I try to keep a few things in mind:

1. Constant inputs should always be wrapped.
2. The value returned by the benchmark does not need to be wrapped because Criterion does it for you.
3. The input from `iter_batched()` does not need to be wrapped because Criterion does it for you.
It was unused, which is a good thing! Yippee!
@BD103 BD103 added C-Code-Quality A section of code that is hard to understand or change A-Reflection Runtime information about types C-Benchmarks Stress tests and benchmarks used to measure how fast things are D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 26, 2024
I'm not all that happy with making `criterion` a normal dependency, but in reality no one is going to build the `benches` crate who doesn't want it as well.
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Dec 26, 2024
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 26, 2024
Merged via the queue into bevyengine:main with commit c03e494 Dec 26, 2024
33 checks passed
@BD103 BD103 deleted the reflect-benchmarks branch December 26, 2024 22:46
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# Objective

- Please see bevyengine#16647 for the full reasoning behind this change.

## Solution

- Create the `bench!` macro, which generates the name of the benchmark
at compile time.

Migrating is a single line change, and it will automatically update if
you move the benchmark to a different module:

  ```diff
  + use benches::bench;

  fn my_benchmark(c: &mut Criterion) {
  -   c.bench_function("my_benchmark", |b| {});
  +   c.bench_function(bench!("my_benchmark"), |b| {});
  }
  ```

- Migrate all reflection benchmarks to use `bench!`.
- Fix a few places where `black_box()` or Criterion is misused.

## Testing

```sh
cd benches

# Will take a long time!
cargo bench --bench reflect

# List out the names of all reflection benchmarks, to ensure I didn't miss anything.
cargo bench --bench reflect -- --list

# Check for linter warnings.
cargo clippy --bench reflect

# Run each benchmark once.
cargo test --bench reflect
```
mrchantey pushed a commit to mrchantey/bevy that referenced this pull request Feb 4, 2025
# Objective

- Please see bevyengine#16647 for the full reasoning behind this change.

## Solution

- Create the `bench!` macro, which generates the name of the benchmark
at compile time.

Migrating is a single line change, and it will automatically update if
you move the benchmark to a different module:

  ```diff
  + use benches::bench;

  fn my_benchmark(c: &mut Criterion) {
  -   c.bench_function("my_benchmark", |b| {});
  +   c.bench_function(bench!("my_benchmark"), |b| {});
  }
  ```

- Migrate all reflection benchmarks to use `bench!`.
- Fix a few places where `black_box()` or Criterion is misused.

## Testing

```sh
cd benches

# Will take a long time!
cargo bench --bench reflect

# List out the names of all reflection benchmarks, to ensure I didn't miss anything.
cargo bench --bench reflect -- --list

# Check for linter warnings.
cargo clippy --bench reflect

# Run each benchmark once.
cargo test --bench reflect
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Benchmarks Stress tests and benchmarks used to measure how fast things are C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants