Avoid native fmod in JsNumber.Create(double) integral detection#2662
Merged
Conversation
TypeConverter.IsIntegralNumber uses `value % 1 == 0`, which compiles to a native fmod call - paid on every Create(double) on arithmetic-heavy workloads (ETW: fmod visible at several percent of self time on SunSpider math scripts). A (long) round-trip equality detects the same integral values: NaN and infinities saturate on the cast and fail the equality, and the explicit range comparisons keep the exact long.MinValue/MaxValue boundary behavior of the previous check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
JsNumber.Create(double)callsTypeConverter.IsIntegralNumber, whosevalue % 1 == 0compiles to a native fmod call — paid on every double boxing, integral or fractional. ETW sampling (ultra @ 8190 Hz) of SunSpider math scripts showsucrtbase!fmodat several percent of main-thread self time in workloads that contain no%operator at all.Replace the check inside
Create(double)with a(long)round-trip equality: NaN and ±Infinity saturate on the cast and fail the equality, fractional values fail it, and the explicit> long.MinValue and < long.MaxValuerange comparisons are kept so the two boundary doubles behave exactly as before.TypeConverter.IsIntegralNumberitself is unchanged — spec consumers (e.g.Number.isInteger) must classify out-of-long-range values like1e300as integral, which the round-trip intentionally does not.Benchmarks (default jobs, vs same-day baseline on same machine)
ETW verification on a spectral-norm load-loop driver:
fmoddisappears from the profile; Native-category self time 540 → 346 ms for identical work.Gates
🤖 Generated with Claude Code