std/sys/unix/time: make it easier for LLVM to optimize Instant
subtraction.
#75545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is the minimal change necessary to get LLVM to optimize
if self.t.tv_nsec >= other.t.tv_nsec
to branchless instructions (at least on x86_64), inspired by @m-ou-se's own attempts at optimizingInstant
subtraction.I stumbled over this by looking at the total number of instructions executed by
rustc -Z self-profile
, and found that after disabling ASLR, the largest source of non-determinism remaining was from thisif
taking one branch or the other, depending on the values involved.The reason this code is even called so many times to make a difference, is that
measureme
(the-Z self-profile
implementation) currently usesInstant::elapsed
for its event timestamps (of which there can be millions).I doubt it's critical to land this, although perhaps it could slightly improve some forms of benchmarking.