-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Rand below should take a NonZero parameter #2519
Conversation
It looks more ugly but it makes API users more correct |
this will have considerably bad impact on performance |
mutators code is a very hot path, it's better not additional overheads.. |
No it's a zero cost abstraction and the compiler can even use the extra bit for other stuff |
The behavior doesn't change. We can also unsafe unwrap if we feel confident about |
The behavor doesn't change, I know. But the assembly code changes. I'm talking about the code that has |
I'm saying this because something similar happened before. semantically same code, but the more "Rusty"-code had caused significant slowdown because it added useless instructions wasting CPU cycles. |
also why can't below() take zero to begin with? |
Right now below doesn't take 0, but it's implicit rather than explicit (with an |
FWIW the current behavior caused troubles in TNO-S3/WuppieFuzz#5 (comment) |
Other option would be to add an additional |
This is better. and all the hotpaths in libafl should use that instead. |
Why do you assume NonZero is slower? It can likely be optimized better than the normal version |
I don't trust the optimization by Rust compiler. As I said, from what I disassembled last time in #1138, it doesn't optimize anything, but just puts useless bound checks just to slow down the stuff. but if you make this compiles we can always count the instructions or the time spent during the mutations to see how they compare |
in your example yes. but if you put if Some(x) == .. or expect() then there's no way NonZero is better |
Most cases that have |
I'll show you an example. In libafl, you are creating NonZero from usize, be it What happens if you create nonzero from usize is Without Nonzero:
THe difference is here, like this, It adds these branches. and I'm saying that even these several lines of additional lines is not good for the mutator. |
You need to optimize in godbolt else it's not useful. |
NonZero with opt-level=3: without NonZero with opt-level=3: Still the one without nonzero is better (in terms of the instruction count inside function |
We can always go back to the unsafe variant if we think we don't need the checks https://godbolt.org/z/rY5ebE9ve |
something like this? https://github.com/AFLplusplus/LibAFL/pull/2496/files#diff-8b8392ab89ae8517f8910eb579121b57031ada7370c32962b75d0cb62ab841a7R133 |
but your point is that "NonZero version could be optimized" which is not the case. (unless unwrap()_unsafe() is used) |
otherwise, why not stick to |
That's what we have now and it breaks at runtime instead of compile time. It's objectively worse. Either we should explicitly allow 0 or explicitly forbid it. NonZero is the compile time way to explicitly forbid it. |
the other solution could be to have a wrapping type for |
So I agree with this
Expose below() as public function for user to use. for internal ones use below_inclusive() |
We can just NonZero and |
There are not too many constants around that need to be NonZero-ed. |
i need to add debug log to check it like last time |
@@ -532,6 +533,11 @@ where | |||
let rand_seed = state.rand_mut().next(); | |||
state.add_metadata::<MOpt>(MOpt::new(mutations.len(), swarm_num, rand_seed)?); | |||
} | |||
let Some(max_stack_pow) = NonZero::new(max_stack_pow) else { |
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'm actually not 100% sure if max_stack_pow of 0 could sometimes make sense(?)
I assumed that not.
i'll measure on weekend |
@tokatoka any news? I'd just merge this tbh, there shouldn't be any overhead |
Didn't we even have CI that tests the performance diff? |
No, don't yet |
Why? |
It's the right thing to do ¯\_(ツ)_/¯ |
Poke @tokatoka |
* Rand below should take a NonZero parameter * More * more * More * fix build * bit of clippy * more clippy * more clippy * More clippy * More more * more nonzero * fix multipart * Cleanup, more unsafe * fix * fix unicode * clippy, fmt * more * More safer and more better * MaxStackPow * fix merge fails * make random_slize_size faster * fix * more * fix
No description provided.