question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance of toLocaleString is slow, due to lack of caching.

See original GitHub issue

Problem

The performance cost of toLocaleString becomes a significant bottleneck when formatting hundreds of dates, e.g. for presentation in a list or grid view. In our case, which is a react app that continously polls for data, this is resulting in significant jank when scrolling.

Root cause

Profiling the code, the root cause seem to be that Luxon instantiates a new Intl.DateTimeFormat every time toLocaleString is called, which has a relatively high cost.

Suggested solution

Since there will only ever be a very limited number of formats, those format instances should be cached after creation. This reduces the runtime of toLocaleString cost by a factor of 10.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
icambroncommented, Nov 3, 2018

Released in 1.4.6. I got an 85x speedup on toLocaleString()

0reactions
pandameistercommented, Nov 3, 2018

awesome, thanks a bunch!

Read more comments on GitHub >

github_iconTop Results From Across the Web

1514851 - Number.prototype.toLocaleString is slow
This has real-world consequences: toLocaleString is so slow that using it in about:memory caused serious performance problems (bug 1517354) that were ...
Read more >
Why Your Cached JavaScript Is Still Slow and Incurs ...
JavaScript, even if Cached, has significant cost on an end user's device; we'll discuss Disk, Parse, Compilation, IPC, and Bytecode Loading.
Read more >
Another Front-End Framework? Here's Why You Should Give ...
These two factors alone make it appealing, but it also invites bad practice and can lead to a disastrous stack with lack of...
Read more >
Untitled
Performance dance tops, Lake texoma party, Caldasia unal, Chuan-kwang, ... Club rentistas uruguay pagina oficial, Jquery tolocalestring format, ...
Read more >
REST API Design Best Practices Handbook – How to Build a ...
Inside the Controller we'll be handling all stuff that is related to HTTP. ... Use data caching for performance improvements.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found