Chart.js: real time chart with High CPU Usage > 300% In Chrome

Created on 24 May 2018  路  6Comments  路  Source: chartjs/Chart.js

I encounter a high cpu usage issue for this sample code after a 5 mins running.

https://codepen.io/orchestor/pen/pLGjqL

Can someone point out any reason on this real time display?

bug

All 6 comments

New Comment: There is no high cpu usage issue when I use Safari browser.

I'm experiencing no issue on Win10 64bit / Chrome 66

What browser version, OS, etc. ?
Did you try to profile what consumes so much CPU?
Are you sure it's related to Chart.js and not another lib or even Chrome extensions?

I am using

  1. mac os 10.11.6.
  2. chrome Version 66.0.3359.139 (Official Build) (64-bit)
  3. tried in chrome incognito mode: same

Here is profile status:

screen shot 2018-06-12 at 11 53 51 am

2.0聽ms0.08聽% | 1698.3聽ms68.06聽% | (anonymous)Chart.bundle.js:8261
2.2聽ms0.09聽% | 1696.2聽ms67.98聽% | startDigestChart.bundle.js:0
1.6聽ms0.07聽% | 1675.5聽ms67.15聽% | callbackChart.bundle.js:0
0聽ms0聽% | 1675.5聽ms67.15聽% | advanceChart.bundle.js:0
3.4聽ms0.14聽% | 1673.7聽ms67.08聽% | renderChart.bundle.js:8877
4.5聽ms0.18聽% | 1669.4聽ms66.90聽% | drawChart.bundle.js:8900
2.3聽ms0.09聽% | 1181.8聽ms47.36聽% | eachChart.bundle.js:14424
2.2聽ms0.09聽% | 1167.7聽ms46.80聽% | (anonymous)Chart.bundle.js:8916
2.0聽ms0.08聽% | 1111.3聽ms44.53聽% | eachChart.bundle.js:0
8.7聽ms0.35聽% | 1092.8聽ms43.80聽% | drawChart.bundle.js:12240
81.8聽ms3.28聽% | 1044.4聽ms41.85聽% | (anonymous)Chart.bundle.js:12386
803.0聽ms32.18聽% | 803.0聽ms32.18聽% | stroke
749.4聽ms30.03聽% | 749.4聽ms30.03聽% | (program)
0聽ms0聽% | 360.1聽ms14.43聽% | clearChart.bundle.js:8511
1.9聽ms0.08聽% | 360.1聽ms14.43聽% | clearChart.bundle.js:14123
358.2聽ms14.36聽% | 358.2聽ms14.36聽% | clearRect
170.5聽ms6.83聽% | 170.5聽ms6.83聽% | fillText
3.4聽ms0.14聽% | 118.4聽ms4.74聽% | drawDatasetsChart.bundle.js:8950
2.7聽ms0.11聽% | 111.2聽ms4.46聽% | drawDatasetChart.bundle.js:8972
2.6聽ms0.10聽% | 104.0聽ms4.17聽% | drawChart.bundle.js:7683
8.0聽ms0.32聽% | 82.2聽ms3.29聽% | drawChart.bundle.js:13840
12.6聽ms0.50聽% | 71.0聽ms2.84聽% | drawChart.bundle.js:16227
4.5聽ms0.18聽% | 70.4聽ms2.82聽% | drawPointChart.bundle.js:14157
1.5聽ms0.06聽% | 58.4聽ms2.34聽% | (anonymous)Chart.bundle.js:0
2.3聽ms0.09聽% | 32.9聽ms1.32聽% | fillTextChart.bundle.js:16299
29.8聽ms1.19聽% | 29.8聽ms1.19聽% | fill
0.1聽ms0.01聽% | 25.3聽ms1.01聽% | (anonymous)pen.js:73
0.4聽ms0.02聽% | 聽

I also tried making a realtime chart and found the performance pretty bad. Here's a flame graph of what I was seeing: https://www.dropbox.com/s/o8ybl413mtjgr2b/Screenshot%202020-05-19%2014.56.58.png?dl=0 -- it seems like creating ticks takes up lots of CPU

@theicfire I would recommend using Chart.js 3.0.0-alpha for anything performance intensive since performance has been the major focus of 3.0. Also, take a look at https://www.chartjs.org/docs/next/general/performance

@theicfire here's a demo of a realtime chart on 3.0: https://github.com/chartjs/Chart.js/issues/7243#issuecomment-631615371

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benmccann picture benmccann  路  3Comments

gabrieldesouza picture gabrieldesouza  路  3Comments

adriantombu picture adriantombu  路  3Comments

gouthamrv picture gouthamrv  路  3Comments

joebirkin picture joebirkin  路  3Comments