Skip to content
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

Address scattergl performance issue with TypeArrays #5632

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/components/color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var tinycolor = require('tinycolor2');
var isNumeric = require('fast-isnumeric');
var isTypedArray = require('../../lib/array').isTypedArray;

var color = module.exports = {};

Expand Down Expand Up @@ -116,7 +117,7 @@ color.clean = function(container) {
if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
for(j = 0; j < val.length; j++) color.clean(val[j]);
}
} else if(val && typeof val === 'object') color.clean(val);
} else if(val && typeof val === 'object' && !isTypedArray(val)) color.clean(val);
}
};

Expand Down
16 changes: 7 additions & 9 deletions src/traces/scattergl/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function calc(gd, trace) {
var hasTooManyPoints = len >= TOO_MANY_POINTS;
var len2 = len * 2;
var stash = {};
var i, xx, yy;
var i;

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

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

// create scene options and scene
Expand Down