-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Repeated x value calculations in updateDatasets #3211
Comments
Hmm, as you noticed this would require code refactoring. But, there's also no guarantee that the x values are always the same for every dataset. For a scatter chart, they can be different. You could add a cache to the time scale so that each value is only calculated once |
This reduces number of calls to momentjs diff() if there are multiple datasets sharing the same labels (chartjs#3211).
This reduces number of calls to momentjs diff() if there are multiple datasets sharing the same labels (chartjs#3211).
020ac35 improves the performance around 3 times for my use case (update() takes now 1 second instead of 3 seconds for M=12, N=4000). I slightly modified the behavior of getPixelForValue() when called with all three parameters. Is such change acceptable? |
Test script that I use is available at https://jsfiddle.net/desowin/j2s46z3o/ |
Previously buildLabelDiffs() was called at the end of buildTicks() and hence labelDiffs cache was calculated twice (in getMinimumBoxSize() and then in fitBox()).
Done in #3261 |
This reduces number of calls to momentjs diff() if there are multiple datasets sharing the same labels (chartjs#3211).
Previously buildLabelDiffs() was called at the end of buildTicks() and hence labelDiffs cache was calculated twice (in getMinimumBoxSize() and then in fitBox()).
updateDatasets function calls update() on every dataset controller which in turn loops on all points and calls updateElement(). Update element calculates x using xScale.getPixelForValue().
If there is a chart with M (example: 12) datasets (N points each, example: 4000) sharing the same label then exactly the same value x gets callculated M times for every updateDatasets() call. This results in O(N*M) calls to getPixelForValue(). As the x values are the same for all datasets it should be possible to optimize this to O(N) calls to getPixelForValue().
Performance improvement would be especially visible when time scale is used, as it calls moment.js diff() function. In example (M=12, N=4000) built-in Chrome profiler shows over 40% of cpu usage for diff() function.
This optimization would require code refactoring. What would be the best way to achieve the goal?
The text was updated successfully, but these errors were encountered: