-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reflect path parsing benchmark #9364
Add reflect path parsing benchmark #9364
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
} | ||
fn random_ident(rng: &mut ChaCha8Rng, f: &mut dyn Write) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
bevy/benches/benches/bevy_ecs/world/world_get.rs
Lines 28 to 30 in b88ff15
fn deterministic_rand() -> ChaCha8Rng { | |
ChaCha8Rng::seed_from_u64(42) | |
} |
# 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.
Objective
We want to measure performance on path reflection parsing.
Solution
Benchmark path-based reflection:
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.