-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Performance improvement for scattergl with many points. Issue #7065 #7301
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
fix: Performance improvement for scattergl with many points. Issue #7065 #7301
Conversation
@archmoj please have a look after the geojson stuff is sorted out - thank you |
I apologize, everyone; I mistakenly referenced the wrong issue. The correct issue number is #7065 sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent PR. 🏆
Many many dancers:
💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃 💃
I'm glad to have been helpful :) |
The performance issues are always intriguing, and I tried to determine why the browser freezes when handling a large number of points. I believe the problem stems from two main factors.
The first factor is the hover effect, which triggers a function that calculates the distance between the mouse pointer and each point in the set. This process can certainly contribute to the performance problem, I believe the best improvement would be using a filter calculated by a window determined by the pointer coordinates with a delta, in this way, we can calculate the distance only for a subset. One possible improvement could be using squared distances for comparison, thereby avoiding the computation of square roots, similar to the method utilized by the K-d tree algorithm, if the plot allows it.
The second factor involves a loop in the part of the code I modified, where "newDistance" is created for every point. This results in excessive overhead for the garbage collector, causing the browser to freeze.
I moved the variable outside the cycle and used a precalculated value for the array length. I conducted tests in the development environments provided by Plotly using the test_dashboard tool.
The values represent average times measured in milliseconds..
The red line shows the performance for the variable inside, the blue line outside. The vertical axis (Y-axis) represents the time measured in milliseconds.

Of course, the performance depends on the engine and the environment in which it runs, but I think this conveys the idea of performance.
Please let me know if this can be the first step to improving performance.