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 regression in Chart.js 3.x vs. 2.x

See original GitHub issue

Expected behavior

I have a site that shows various graphs of Covid-19 spread in different countries and regions, at https://mackuba.eu/corona/, which uses Chart.js. I’ve been maintaining it since March 2020, and at the beginning the charts worked fine since there wasn’t much data to show, but the datasets were getting longer and longer, and last year already it was working kind of slow. It’s especially bad in Chrome and Firefox, surprisingly it’s much better in Safari.

I’ve built it in Chart.js 2.x, since 3.0 only came out last year. I read that 3.x includes some performance improvements, so I thought it would fix the problem.

I struggled for some time with an issue with TypeScript definitions, which changed in 3.x, but I couldn’t figure it out and in the end I worked around it by marking all Chart.js types as any.

I managed to update all the calls to Chart.js to the 3.x API and started testing the site. The result was… unexpected. The site seems to work just as slow in Chrome, but now it also works slower in Safari…

I’ve managed to extract a minimal code sample that shows the issue to a new repo: https://github.com/mackuba/chart_slow_demo. It’s a bit of an extreme example, because it shows 20 datasets with the full date range (since March 2020), and normally there’s a few up to 10 datasets and a smaller date range - but this way the problem is more obvious. You can make the chart “lighter” by removing some items from the population dictionary.

Current behavior

In Chrome (Brave):

  • chartjs2.html (2.9.3): works slow (animation starts quickly but is like 3 fps)
  • chartjs3.html (3.7.0): slow, but in a different way (for more than half a second nothing is happening)

In Safari:

  • chartjs2.html (2.9.3): works ok - animation starts immediately and is faster than in Chrome
  • chartjs3.html (3.7.0): there’s almost a second of delay before the chart starts animating

I’m testing this on 2018 MacBook Pro (macOS 11.6.2) - if you’re checking it on a fast computer like M1 Macs and it loads immediately, try on an older machine.

Safari version: Version 14.1.2 Brave version: Version 1.34.80 Chromium: 97.0.4692.71 (Official Build) (x86_64)

Reproducible sample

https://github.com/mackuba/chart_slow_demo

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v3.7.0

Browser name and version

Safari 14.1.2

Link to your project

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LeeLenaleeecommented, Oct 5, 2022

Closed it because it’s a duplicate

0reactions
Orilliancommented, Oct 5, 2022

Has there been any headway on this? In testing these issues continue even with the latest release. 😞

@LeeLenaleee you closed the related ticket above as not planned?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance | Chart.js
Chart.js is fastest if you provide data with indices that are unique, sorted, and consistent across datasets and provide the normalized: true ...
Read more >
How to draw a linear regression line in Chart.js - Stack Overflow
I typically use the regression package. First, add the package as an external script. Second, clean your data. Just basic checks here:
Read more >
Regression Line Chart JS | ChartJS 2.9.x - YouTube
Regression Line Chart JS | ChartJS 2.9. x. In this video we will explore how to build the formula to draw the Regression...
Read more >
Highcharts.com - Highcharts
Highcharts pareto chart JavaScript example visualizes percentage restaurant complaints by combining line and vertical bar graphs. Pareto chart · Highcharts ...
Read more >
How to generate a linear regression Chart.Js - Laracasts
How to generate a linear regression Chart.Js ... type: 'line', data: { labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,...
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