Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Intl.DateTimeFormat to reduce memory footprint #10

Merged
merged 1 commit into from
Jul 9, 2021
Merged

Cache Intl.DateTimeFormat to reduce memory footprint #10

merged 1 commit into from
Jul 9, 2021

Conversation

ferk6a
Copy link
Contributor

@ferk6a ferk6a commented Jul 9, 2021

Creating Intl.DateTimeFormat instances in V8 is very 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 deliberately avoided. This is due to the fact that the user's time zone may change during the execution of a program. An example is calling Temporal.now.zonedDateTimeISO() which should always output the correct time zone. This shouldn't be a problem for server-sided code which usually doesn't (or rather, shouldn't) use the time zone from the environment for calculations.

This fixes #7.

Creating Intl.DateTimeFormat instances in V8 is very 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 deliberately
avoided. This is due to the fact that the user's time zone may change during
the execution of a program. An example is calling Temporal.now.zonedDateTimeISO()
which should always output the correct time zone. This shouldn't be a problem
for server-sided code which usually doesn't (or rather, shouldn't) use the
time zone from the environment for calculations.
Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @justingrant already reviewed this in the issue thread, but it looks good to me too.

@ptomato ptomato merged commit d6335df into js-temporal:main Jul 9, 2021
justingrant added a commit to justingrant/proposal-temporal that referenced this pull request Jul 10, 2021
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)
ptomato pushed a commit to tc39/proposal-temporal that referenced this pull request Jul 12, 2021
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)
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.

Reducing memory footprint by reusing Intl.DateTimeFormat instances
2 participants