Skip to content

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

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Performance improvement for scattergl with many points. Issue #7056
  • Loading branch information
giuseppe-straziota committed Dec 7, 2024
commit f6028d00b97aadf25df9b1bd8ea6edbc7290df70
9 changes: 7 additions & 2 deletions src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ exports.getClosest = function(cd, distfn, pointData) {
// this is the longest loop... if this bogs down, we may need
// to create pre-sorted data (by x or y), not sure how to
// do this for 'closest'
for(var i = 0; i < cd.length; i++) {
var newDistance = distfn(cd[i]);

// defined outside the for to improve the garbage collector performance
var newDistance = Infinity;
// the browser engine typically optimizes the length, but it is outside the cycle if it does not
var len = cd.length
for(var i = 0; i < len; i++) {
newDistance = distfn(cd[i]);
if(newDistance <= pointData.distance) {
pointData.index = i;
pointData.distance = newDistance;
Expand Down