Replace double/float IsNaN + IsInfinity checks with optimized IsFinite #10690
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.
Description
Several versions ago,
IsFinite
was introduced as an intrinsic, therefore there's no need to perform two separate checks for the same thing, it simplifies the code, uses less bytes and the codegen is also smaller and more efficient.I've also cleaned up some of the unused util methods in that domain.
Simple benchmark
There are a few places I didn't remove these checks, that should be done separately. Those are constructors that emit different messages for
NaN
andInfinity
. We should have a discussion on how to approach this. As those are all exception cases, ideal approach is probably to create a non-inlinable throw helper that further then checksIsNaN
/IsInfinity
in caseIsFinite
already fails and throws the exception with correct messages. Would reduce the ctor complexity for an uncommon case, though it will start to matter a bit less in .NET 10+ as methods with EH frames will now be inlinable.P.S. That
DoubleValue_Validate
fromDocumentViewer
is the real legacy code gem that should have been preserved I guess.Customer Impact
Improved performance, decreased allocations.
Regression
No.
Testing
Local build.
Risk
Medium, I was doing all of these replacements manually and thus this is rather error-prone where I could invert a condition badly and I didn't notice it. Review carefully this one please, thank you.
Microsoft Reviewers: Open in CodeFlow