-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Optimize the performance of scatter trace sorting comparator with map #1555
Conversation
Construct a map rather than an array to improve the performance of index search. Jasmine tests passed.
Looks good to me. @rreusser can you think of any side effects (e.g. for animations)? |
@@ -51,13 +51,13 @@ module.exports = function plot(gd, plotinfo, cdscatter, transitionOpts, makeOnCo | |||
// Sort the traces, once created, so that the ordering is preserved even when traces | |||
// are shown and hidden. This is needed since we're not just wiping everything out | |||
// and recreating on every update. | |||
for(i = 0, uids = []; i < cdscatter.length; i++) { | |||
uids[i] = cdscatter[i][0].trace.uid; | |||
for(i = 0, uids = {}; i < cdscatter.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems entirely equivalent to me 👍
I didn't anticipate this would be more than like 10-15 or so, which would make the overhead of indexOf negligible. I'll keep this in mind when contemplating orders of magnitude!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, actually there is almost no difference on map and array here if the amount of trace is small. My cases might be a bit crazy (with 5000+ traces). But it seems worthwhile to use map instead here since there is almost no side effect.
Suggested benchmark strategy for this case (though end-to-end is relevant too): var t0 = performance.now() // if your browser supports it, otherwise Date.now()
... the above lines of code before, then after
var t1 = performance.now()
console.log('Time taken to sort:', t0 - t1) The fix seems appropriate either way (I should have known better in the first place 🙄 ), it's just very useful to have a sense for the cost and gains of optimizations like this. |
Here is my script. |
@hy9be thanks for that! |
By the way, @hy9be thanks for all your contributions this week! You get my vote for contributor of the week 🏆 |
Wow...feel flattered. Thanks! I had some exposure to the idea of grammar of graphics. Plotly is not quite an implementation of that but the design is much more orthogonal and abstract than most other charting libraries. I like the project. Will try to help more. |
Thanks for the benchmark! Honestly I didn't think that single call would make a big enough difference to have that obvious of an effect in an end-to-end test. 🐢 |
Construct a map rather than an array to improve the performance of index search. Jasmine tests passed.