Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6028d0

Browse files
fix: Performance improvement for scattergl with many points. Issue #7056
1 parent f8c7b5d commit f6028d0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/fx/helpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ exports.getClosest = function(cd, distfn, pointData) {
6060
// this is the longest loop... if this bogs down, we may need
6161
// to create pre-sorted data (by x or y), not sure how to
6262
// do this for 'closest'
63-
for(var i = 0; i < cd.length; i++) {
64-
var newDistance = distfn(cd[i]);
63+
64+
// defined outside the for to improve the garbage collector performance
65+
var newDistance = Infinity;
66+
// the browser engine typically optimizes the length, but it is outside the cycle if it does not
67+
var len = cd.length
68+
for(var i = 0; i < len; i++) {
69+
newDistance = distfn(cd[i]);
6570
if(newDistance <= pointData.distance) {
6671
pointData.index = i;
6772
pointData.distance = newDistance;

0 commit comments

Comments
 (0)