Skip to content

Commit 32a8e8f

Browse files
Serafim BarrocaSerafim Barroca
Serafim Barroca
authored and
Serafim Barroca
committed
Address performance issue with ArrayBuffers
Address an unavoidable loop phase inside color clean function where it iterates all over the graph points if data used is an ArrayBuffer. This causes graph to have way less performance relative to Array types.
1 parent 65f739d commit 32a8e8f

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/components/color/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ color.clean = function(container) {
116116
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
117117
for(j = 0; j < val.length; j++) color.clean(val[j]);
118118
}
119-
} else if(val && typeof val === 'object') color.clean(val);
119+
} else if(val && typeof val === 'object' && !ArrayBuffer.isView(val)) color.clean(val);
120120
}
121121
};
122122

src/traces/scattergl/calc.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function calc(gd, trace) {
2727
var hasTooManyPoints = len >= TOO_MANY_POINTS;
2828
var len2 = len * 2;
2929
var stash = {};
30-
var i, xx, yy;
30+
var i;
3131

3232
var origX = xa.makeCalcdata(trace, 'x');
3333
var origY = ya.makeCalcdata(trace, 'y');
@@ -42,11 +42,12 @@ module.exports = function calc(gd, trace) {
4242
// we need hi-precision for scatter2d,
4343
// regl-scatter2d uses NaNs for bad/missing values
4444
var positions = new Array(len2);
45+
var _ids = new Array(len);
4546
for(i = 0; i < len; i++) {
46-
xx = x[i];
47-
yy = y[i];
48-
positions[i * 2] = xx === BADNUM ? NaN : xx;
49-
positions[i * 2 + 1] = yy === BADNUM ? NaN : yy;
47+
positions[i * 2] = x[i] === BADNUM ? NaN : x[i];
48+
positions[i * 2 + 1] = y[i] === BADNUM ? NaN : y[i];
49+
// Pre-compute ids.
50+
_ids[i] = i;
5051
}
5152

5253
if(xa.type === 'log') {
@@ -66,10 +67,7 @@ module.exports = function calc(gd, trace) {
6667
// FIXME: delegate this to webworker
6768
stash.tree = cluster(positions);
6869
} else {
69-
var ids = stash.ids = new Array(len);
70-
for(i = 0; i < len; i++) {
71-
ids[i] = i;
72-
}
70+
stash.ids = _ids;
7371
}
7472

7573
// create scene options and scene

0 commit comments

Comments
 (0)