unwrap_or_else(|| debug_unreachable_unchecked()) still generates jump instructions #5064
Labels
A-ECS
Entities, components, systems, and events
C-Code-Quality
A section of code that is hard to understand or change
C-Performance
A change motivated by improving speed, memory usage or compile times
What problem does this solve or what need does it fill?
When writing the core
Fetch
related code, there's a large amount ofunwrap_or_else(|| debug_unreachable_unchecked()
to suggest to the compiler that, in release builds, theOption
is neverNone
and unwrapping is always safe. This is supposed to hint to the compiler that this branch is dead.However, when attempting to compare this pattern against an actual
get_unchecked
implementation forSparseSet
s seems to still generates two jump instructions (at least on x86 platforms). You can see this here: https://godbolt.org/z/e3EPE1vxW, the full assembly output has been copied below.What solution would you like?
Internal,
pub(crate)
get_unchecked(_mut)
variants on SparseSet and derivative metadata stores and storages that is only used for release builds.What alternative(s) have you considered?
Leaving this untouched. Eat the performance penalty.
The text was updated successfully, but these errors were encountered: