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

Speed up toLocaleString ~2.5x by optimizing creation of Intl.DateTimeFormat instances #1651

Merged
merged 1 commit into from
Jul 16, 2021

Conversation

justingrant
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Jul 16, 2021

Codecov Report

Merging #1651 (aed271a) into main (cc38541) will decrease coverage by 22.20%.
The diff coverage is 91.42%.

❗ Current head aed271a differs from pull request most recent head a69e0fd. Consider uploading reports for the commit a69e0fd to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1651       +/-   ##
===========================================
- Coverage   95.00%   72.79%   -22.21%     
===========================================
  Files          19       18        -1     
  Lines       10726     4838     -5888     
  Branches     1716     1058      -658     
===========================================
- Hits        10190     3522     -6668     
- Misses        523     1030      +507     
- Partials       13      286      +273     
Flag Coverage Δ
test262 72.79% <91.42%> (-0.01%) ⬇️
tests ?

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

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 82.79% <ø> (-12.28%) ⬇️
polyfill/lib/intl.mjs 65.55% <91.42%> (-34.45%) ⬇️
polyfill/lib/calendar.mjs 23.22% <0.00%> (-71.15%) ⬇️
polyfill/lib/instant.mjs 79.13% <0.00%> (-15.31%) ⬇️
polyfill/lib/plainmonthday.mjs 79.01% <0.00%> (-14.14%) ⬇️
polyfill/lib/plainyearmonth.mjs 83.42% <0.00%> (-12.99%) ⬇️
polyfill/lib/plaindatetime.mjs 85.14% <0.00%> (-12.17%) ⬇️
polyfill/lib/timezone.mjs 81.66% <0.00%> (-11.80%) ⬇️
... and 9 more

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 cc38541...a69e0fd. Read the comment docs.

@justingrant
Copy link
Collaborator Author

This PR wraps up a group of three DateTimeFormat optimization PRs. (The others were #1624 and #1629.)

Two weeks ago, demitasse tests took 46s-49s in CI. This PR only took 32s... 30% less time!

@@ -8,7 +8,7 @@
"types": "index.d.ts",
"scripts": {
"coverage": "c8 report --reporter html",
"test": "node --no-warnings --experimental-modules --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
"test": "time node --no-warnings --experimental-modules --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do. If OK with you, I'd like to leave it in the other repo. Especially as we start attracting new contributors over there, I'd like to instill awareness of perf regressions from everyone contributing code over there. Unless it hurts something?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't suppose it hurts, but I'm slowly removing these tests anyway, so their runtime doesn't matter much here. If you want to think about ways to speed up the 262 tests, that'd help me more :)

Comment on lines 1062 to 1064
toJSON() {
if (++this.calls > 1) throw new RangeError('prop read twice');
return value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this ever be called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. An early version of this PR used a JSON round-trip as a cheap way to do a deep copy of the input parameters, so this was previously useful. Now it's implemented differently so this toJSON test code will never run. I'll remove it, unless you think there's value in leaving it around in case some future implementation decides to use JSON.stringify on the inputs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm happy to keep it and add valueOf as well, or just drop it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just dropped it for simplicity. We already have to revisit this per js-temporal/temporal-polyfill#12 (comment) so any improvement in multi-call/proxy-calll tests could happen then.

I think we're good to merge. It's pretty late for me so I'm going to bed soon. If I can't stay up until the Test262 run finishes, I'll merge in the morning if you don't do it first. Then I can go on vacation! :-)

Speed up toLocaleString ~2.5x by optimizing creation of
Intl.DateTimeFormat instances.

Port of js-temporal/temporal-polyfill#12
@justingrant justingrant force-pushed the speedup-tolocalestring branch from da763e0 to a69e0fd Compare July 16, 2021 12:46
@Ms2ger Ms2ger merged commit 88bad4d into tc39:main Jul 16, 2021
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.

2 participants