plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
17.05k stars 1.86k forks source link

Contour perf: get rid of join(',') #1311

Closed alexcjohnson closed 5 years ago

alexcjohnson commented 7 years ago

In our marching squares algorithm, we have a lot of statements that amount to indicesStr = indices.join(','). These make the code a little clearer (you can do a single === to find out if two locations are the same) but have a substantial perf cost:

timeit(function(v) { return v.join(',') === '2,2'; }, [2,3], 1000000)
0.00024889000000001397

timeit(function(v) { return v[0] === 2 && v[1] === 2; }, [2,3], 1000000)
0.000011064999999944121

Lets replace them with straight-up integer comparisons.

rreusser commented 7 years ago

Like these? https://github.com/plotly/plotly.js/blob/master/src/traces/contour/find_all_paths.js#L89