Construct new Date() from clock ticks without intermediate conversions#2609
Merged
Conversation
The zero-argument Date construction path computed (GetUtcNow().DateTime - Epoch).TotalMilliseconds - a DateTimeOffset -> DateTime -> TimeSpan -> double chain - and then re-validated the value through TimeClip inside the JsDate constructor. The milliseconds now come straight from ticks ((UtcTicks - EpochTicks) / TicksPerMillisecond), and a clip-free internal constructor stores them directly: integer division truncates toward zero exactly like TimeClip for positive values, and a ticks-derived current time is always inside the clip range. The subclass path (OrdinaryCreateFromConstructor) keeps the spec pipeline. DateConstructionBenchmarks A/B (default job, adjacent runs): | row | before | after | | |---------------|----------|----------|--------------------------| | NewDateNow | 9.060 ms | 8.048 ms | -11.2% (90.6 -> 80.5 ns) | | NewDateMillis | 11.66 ms | 11.81 ms | flat (launchCount-5 median; single-launch +7.6% was a process mode) | Allocations byte-identical. The stopwatch row's expected ~1% gain sits inside its noise floor (driver read flat) - this is a micro-path win on the ~13% of that row spent constructing dates. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
lahma
enabled auto-merge (squash)
July 9, 2026 08:53
This was referenced Jul 13, 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.
What
The zero-argument
new Date()path computed(GetUtcNow().DateTime - Epoch).TotalMilliseconds— aDateTimeOffset → DateTime → TimeSpan → doublechain — and then re-validated the value throughTimeClipinside theJsDateconstructor. The milliseconds now come straight from ticks(
(UtcTicks − EpochTicks) / TicksPerMillisecond), and a clip-free internal constructor stores themdirectly: integer division truncates toward zero exactly like
TimeClipfor positive values, and aticks-derived current time is always inside the clip range. The subclass path
(
OrdinaryCreateFromConstructor) keeps the spec pipeline.Results
DateConstructionBenchmarks A/B (default job, adjacent runs):
new Date())Allocations byte-identical. Honest framing for stopwatch.js (which spends ~13% of its time in
new Date(), ~196k per op): the expected ~1% row gain sits inside the row's noise floor — the±0.7% wall-clock driver read flat — so this is a micro-path win, not a row mover.
Gating
All-TFM build ✅ · Jint.Tests ×2 ✅ · PublicInterface ×2 ✅ · Test262 99,426/0 ✅
🤖 Generated with Claude Code