Skip to content
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

Performance improvements #6729

Merged
merged 2 commits into from
Nov 11, 2019
Merged

Performance improvements #6729

merged 2 commits into from
Nov 11, 2019

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Nov 11, 2019

Couple of performance improvements (still using uPlot benchmark for testing)

  • Nearest mode: Start finding nearest items at the index linearly in the mouse position. Then look in both directions as long as distance decreases.
  • Line: Stop cloning points when the array is not going to be altered
  • Point: stop falling back to defaults (is handled in config resolution), don't draw when radius <= 0

I guess next major thing would be simplifying paths

@etimberg
Copy link
Member

On the topic of simplifying paths, this algorithm works very well since it retains peaks in the data. I've implemented it before in JS and could easily render 200k points with real-time updates.

The simple optimization is to have max 4 points per pixel, but there are a number of other optimizations that come in as well that can usually reduce that even further.

@@ -48,6 +48,7 @@ class Line extends Element {
}

if (me._loop) {
points = points.slice(); // clone array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch! I had noticed this clone taking awhile, but didn't see that we could move it to occur here

@etimberg etimberg merged commit d5b6698 into chartjs:master Nov 11, 2019
@etimberg etimberg added this to the Version 3.0 milestone Nov 11, 2019
@kurkle kurkle deleted the more-performance branch November 13, 2019 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants