moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.05k stars 728 forks source link

Perf: Summary of all perf changes. DO NOT MERGE. #1584

Open schleyfox opened 5 months ago

schleyfox commented 5 months ago

We have worked to improve luxon performance for our use case of parsing/formatting hundreds of thousands of dates at a time. These are represented as a series of independent PRs

perf

  1. https://github.com/moment/luxon/pull/1574
  2. https://github.com/moment/luxon/pull/1576
  3. https://github.com/moment/luxon/pull/1579
  4. https://github.com/moment/luxon/pull/1580
  5. https://github.com/moment/luxon/pull/1581
  6. https://github.com/moment/luxon/pull/1582

bug fix/quality of life

  1. https://github.com/moment/luxon/pull/1575
  2. https://github.com/moment/luxon/pull/1583

While each perf-related PR improves perf on its own, we see the most benefit when they are all combined (especially for time zone offset handling).

Benchmark Comparison (name | before | after | after/before):

DateTime.fromObject with locale | 1,112,953 ±0.08% | 1,229,589 ±0.17% | 1.1x
DateTime.local with numbers | 844,898 ±0.15% | 965,500 ±0.15% | 1.14x
DateTime.local with numbers and zone | 50,913 ±0.18% | 183,955 ±0.17% | 3.61x
DateTime.fromFormat | 60,666 ±0.17% | 115,620 ±0.21% | 1.91x
DateTime.fromFormat with zone | 26,687 ±0.18% | 56,353 ±0.23% | 2.11x
DateTime.fromFormatParser |     | 418,416 ±0.12%
DateTime.fromFormatParser with zone |       | 98,700 ±0.24%
fromFormat vs. fromFormatParser | 60,666 ±0.17% | 418,416 ±0.12% | 6.9x
fromFormat vs. fromFormatParser with zone | 26,687 ±0.18% | 98,700 ±0.24% | 3.7x
DateTime#setZone | 175,791 ±0.29% | 301,550 ±0.34% | 1.72x
linux-foundation-easycla[bot] commented 5 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

schleyfox commented 5 months ago

/easycla

icambron commented 4 months ago

@schleyfox Hey Ben -- these are great, and I really like the effort and depth here. I've merged most of them. The remaining items are:

schleyfox commented 4 months ago

@icambron thanks!

for #1579 I'll get that fixed shortly

for #1580 I'll benchmark that and respond, should be straightforward.

for #1583 totally! It's been on my backlog to docker up an example to see how the npm hooks behave under different conditions (I'm quite confused), but I haven't had a chance yet.