Skip to content

Conversation

justingrant
Copy link
Collaborator

Creating Intl.DateTimeFormat instances in V8 is slow and memory heavy. ES.GetFormatterParts and ES.GetCanonicalTimeZoneIdentifier are functions that are called many times when using Temporal, and they used to create new instances of Intl.DateTimeFormat for each call. In this commit, we cache them using the time zone identifier as the key.

It should be noted that doing the same to SystemTimeZone was avoided. This is due to the fact that user's time zone may change during the execution of a program. An example: Temporal.now.zonedDateTimeISO() should always output the correct time zone. This shouldn't be a problem for server-side code that usually doesn't (or rather, shouldn't) use the time zone from the environment for calculations.

This PR was ported from js-temporal/temporal-polyfill#10.

Creating Intl.DateTimeFormat instances in V8 is slow and memory heavy.
GetFormatterParts and GetCanonicalTimeZoneIdentifier are functions that
are called many times when using Temporal, and they used to create new
instances of Intl.DateTimeFormat for each call. In this commit, we cache
them using the time zone identifier as the key.

It should be noted that doing the same to SystemTimeZone was
avoided. This is due to the fact that user's time zone may change during
the execution of a program. An example: Temporal.now.zonedDateTimeISO()
should always output the correct time zone. This shouldn't be a problem
for server-side code that usually doesn't (or rather, shouldn't) use
the time zone from the environment for calculations.

(ported from js-temporal/temporal-polyfill#10)
@justingrant justingrant added the non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! label Jul 10, 2021
@justingrant justingrant requested review from ptomato and Ms2ger July 10, 2021 01:21
@codecov
Copy link

codecov bot commented Jul 10, 2021

Codecov Report

Merging #1629 (48f6c83) into main (44995c7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1629   +/-   ##
=======================================
  Coverage   95.00%   95.00%           
=======================================
  Files          19       19           
  Lines       10724    10726    +2     
  Branches     1714     1716    +2     
=======================================
+ Hits        10188    10190    +2     
  Misses        523      523           
  Partials       13       13           
Flag Coverage Δ
test262 72.80% <100.00%> (+0.03%) ⬆️
tests 90.09% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.06% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44995c7...48f6c83. Read the comment docs.

@ptomato
Copy link
Collaborator

ptomato commented Jul 12, 2021

This speeds up the tests which are painfully slow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants