-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Consider using unreachable_unchecked in hot spots #52945
Comments
I've been saved by the compiler panicking with "entered unreachable code" quite a few times. Especially during development where one might end up making such code reachable (maybe because a new features was implemented and some other code correctly assumed that it was unreachable before the existence of the new feature). Having these silently become UB seems... suboptimal. |
That's why I'm suggesting adding |
cc @nnethercote |
To be honest, I wouldn't trust a microbenchmark very much for this kind of change. I think the behaviour in real code could be quite different. But it might be worth doing a mass change and then measuring to see if it makes a difference in practice. If it does, then it's reasonable to have a discussion about whether the speed up is worth the functionality changes. |
It's not worth doing in most cases, because:
|
I would like to see @nnethercote's suggestion benchmarked -- blindly replace every |
A perf run with all the |
hint::unreachable_unchecked
is nearly twice as fast as its safe counterpart (benchmarks for 1000 matches):It might be a good idea to use it in hot 🔥 spots where we are super sure™️ we won't ever reach it or with
debug_assert
s right before it.I have
ripgrep
ped (ar
-g
eed?) forunreachable!()
s in the compiler (list below) but I don't know which ones are hot enough. If this is a good idea I'd be happy to change them if anyone can advise where this should be considered.unreachable!()s
The text was updated successfully, but these errors were encountered: