Skip to content

Add reflect path parsing benchmark#9364

Merged
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
nicopap:reflect-path-benchmark
Aug 25, 2023
Merged

Add reflect path parsing benchmark#9364
alice-i-cecile merged 1 commit into
bevyengine:mainfrom
nicopap:reflect-path-benchmark

Conversation

@nicopap

@nicopap nicopap commented Aug 5, 2023

Copy link
Copy Markdown
Contributor

Objective

We want to measure performance on path reflection parsing.

Solution

Benchmark path-based reflection:

  • Add a benchmark for ParsedPath::parse

It's fairly noisy, this is why I added the 3% threshold.

Ideally we would fix the noisiness though. Supposedly I'm seeding the RNG correctly, so there shouldn't be much observable variance. Maybe someone can help spot the issue.

@nicopap nicopap added C-Performance A change motivated by improving speed, memory usage or compile times A-Reflection Runtime information about types labels Aug 5, 2023
@nicopap nicopap changed the title Add path parsing benchmark Add reflect path parsing benchmark Aug 5, 2023
@nicopap nicopap added this to the 0.12 milestone Aug 6, 2023

@tbillington tbillington left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

Comment on lines +21 to +22
}
fn random_ident(rng: &mut ChaCha8Rng, f: &mut dyn Write) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space here ideally :P

const SIZES: [usize; 6] = [100, 3160, 1000, 3_162, 10_000, 24_000];

fn deterministic_rand() -> ChaCha8Rng {
ChaCha8Rng::seed_from_u64(42)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: would also accept inlining this since it's only used in one place, optionally moving the seed to a named const, but not necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-used the function from benches/benches/bevy_ecs/world/world_get.rs

fn deterministic_rand() -> ChaCha8Rng {
ChaCha8Rng::seed_from_u64(42)
}

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Aug 25, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 25, 2023
Merged via the queue into bevyengine:main with commit 7b0809b Aug 25, 2023
github-merge-queue Bot pushed a commit that referenced this pull request Aug 25, 2023
# Objective

All delimiter symbols used by the path parser are ASCII, this means we
can entirely ignore UTF8 handling. This may improve performance.

## Solution

Instead of storing the path as an `&str` + the parser offset, and
reading the path using `&self.path[self.offset..]`, we store the parser
state in a `&[u8]`. This allows two optimizations:

1. Avoid UTF8 checking on `&self.path[self.offset..]`
2. Avoid any kind of bound checking, since the length of what is left to
read is stored in the `&[u8]`'s reference metadata, and is assumed valid
by the compiler.

This is a major improvement when comparing to the previous parser.

1. `access_following` and `next_token` now inline in `PathParser::next`
2. Benchmarking show a 20% performance increase (#9364)

Please note that while we ignore UTF-8 handling, **utf-8 is still
supported**. This is because we only handle "at the edges" what happens
exactly before and after a recognized `SYMBOL`. utf-8 is handled
transparently beyond that.
@nicopap nicopap deleted the reflect-path-benchmark branch August 30, 2023 13:35
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-Performance A change motivated by improving speed, memory usage or compile times 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