From f6028d00b97aadf25df9b1bd8ea6edbc7290df70 Mon Sep 17 00:00:00 2001 From: giuseppe straziota Date: Sat, 7 Dec 2024 14:48:26 +0100 Subject: [PATCH 1/4] fix: Performance improvement for scattergl with many points. Issue #7056 --- src/components/fx/helpers.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/fx/helpers.js b/src/components/fx/helpers.js index f11e5266ef7..8ba0d2fa254 100644 --- a/src/components/fx/helpers.js +++ b/src/components/fx/helpers.js @@ -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; From 50b0874f6584a3ee6a58d34cb40829a739bb51cd Mon Sep 17 00:00:00 2001 From: giuseppe straziota Date: Sat, 7 Dec 2024 15:37:18 +0100 Subject: [PATCH 2/4] Chore: add changelog entry for PR #7301 --- draftlogs/7310_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/7310_fix.md diff --git a/draftlogs/7310_fix.md b/draftlogs/7310_fix.md new file mode 100644 index 00000000000..efdbde46602 --- /dev/null +++ b/draftlogs/7310_fix.md @@ -0,0 +1 @@ +- Fix: Performance improvement for scattergl with many points [[#7301](https://github.com/plotly/plotly.js/pull/7301)] \ No newline at end of file From 478aedfaffd0b612fb48254aca5ac21eebcbf681 Mon Sep 17 00:00:00 2001 From: giuseppe straziota Date: Tue, 10 Dec 2024 19:09:57 +0100 Subject: [PATCH 3/4] Chore: renamed correctly the file name PR #7301 --- draftlogs/{7310_fix.md => 7301_fix.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename draftlogs/{7310_fix.md => 7301_fix.md} (100%) diff --git a/draftlogs/7310_fix.md b/draftlogs/7301_fix.md similarity index 100% rename from draftlogs/7310_fix.md rename to draftlogs/7301_fix.md From 4c35d1c7862be2fecc626d13c94d448ad5c9f5b2 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi <33888540+archmoj@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:31:37 -0500 Subject: [PATCH 4/4] Update draftlogs/7301_fix.md --- draftlogs/7301_fix.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/draftlogs/7301_fix.md b/draftlogs/7301_fix.md index efdbde46602..a98abe40f66 100644 --- a/draftlogs/7301_fix.md +++ b/draftlogs/7301_fix.md @@ -1 +1,2 @@ -- Fix: Performance improvement for scattergl with many points [[#7301](https://github.com/plotly/plotly.js/pull/7301)] \ No newline at end of file +- Performance improvement for scattergl traces with many points [[#7301](https://github.com/plotly/plotly.js/pull/7301)], + with thanks to @giuseppe-straziota for the contribution! \ No newline at end of file