Skip to content

Comments

Optimize Date operations and object resolution#2288

Draft
lahma wants to merge 1 commit intosebastienros:mainfrom
lahma:stopwatch-perf
Draft

Optimize Date operations and object resolution#2288
lahma wants to merge 1 commit intosebastienros:mainfrom
lahma:stopwatch-perf

Conversation

@lahma
Copy link
Collaborator

@lahma lahma commented Feb 16, 2026

Three targeted optimizations for Date-heavy workloads:

  1. TypeConverter.ToNumeric: Fast path for JsDate objects Bypasses the expensive ToPrimitive chain (Symbol.toPrimitive lookup -> exotic call -> OrdinaryToPrimitive -> valueOf -> ThisTimeValue) by directly returning the date's numeric value. Eliminates ~12 method calls per Date-to-number conversion.

  2. DateConstructor.Construct: Skip OrdinaryCreateFromConstructor for new Date() When newTarget is the built-in DateConstructor (the common case), directly construct JsDate with the known prototype instead of going through GetPrototypeFromConstructor which does a property lookup.

  3. Engine.GetValue: Direct ObjectInstance cast When baseValue.IsObject() is already confirmed, use a direct cast instead of TypeConverter.ToObject() which performs a redundant type check.

StopwatchBenchmark results (ShortRun):

Variant Before After Improvement
Classic Execute 251.4 ms 225.3 ms -10.4%
Classic ParsedScript 264.3 ms 231.0 ms -12.6%
Modern Execute 302.6 ms 271.9 ms -10.1%
Modern ParsedScript 320.2 ms 277.8 ms -13.2%

…watch benchmark improvement

Three targeted optimizations for Date-heavy workloads:

1. TypeConverter.ToNumeric: Fast path for JsDate objects
   Bypasses the expensive ToPrimitive chain (Symbol.toPrimitive lookup ->
   exotic call -> OrdinaryToPrimitive -> valueOf -> ThisTimeValue) by
   directly returning the date's numeric value. Eliminates ~12 method
   calls per Date-to-number conversion.

2. DateConstructor.Construct: Skip OrdinaryCreateFromConstructor for new Date()
   When newTarget is the built-in DateConstructor (the common case),
   directly construct JsDate with the known prototype instead of going
   through GetPrototypeFromConstructor which does a property lookup.

3. Engine.GetValue: Direct ObjectInstance cast
   When baseValue.IsObject() is already confirmed, use a direct cast
   instead of TypeConverter.ToObject() which performs a redundant type
   check.

StopwatchBenchmark results (ShortRun):

| Variant              | Before   | After    | Improvement |
|----------------------|----------|----------|-------------|
| Classic Execute      | 251.4 ms | 225.3 ms | -10.4%      |
| Classic ParsedScript | 264.3 ms | 231.0 ms | -12.6%      |
| Modern Execute       | 302.6 ms | 271.9 ms | -10.1%      |
| Modern ParsedScript  | 320.2 ms | 277.8 ms | -13.2%      |

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant