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

Increased speed by caching all possible selections #1

Closed
wants to merge 1 commit into from
Closed

Increased speed by caching all possible selections #1

wants to merge 1 commit into from

Conversation

ZJONSSON
Copy link

This quick hack avoids having to go through all the rectangles and focuses on two groups of nodes: the last one selected (need to turn color back off) and the new selection. All possible selections have been cached in the node object.

@NelsonMinar
Copy link
Owner

Thanks! I'm just about to go out of town and need to look at this more closely: part of my goal with this code is to keep it very simple for a talk I'm giving. But I like the idea of caching, will give it proper attention in about 10 days.

@ZJONSSON
Copy link
Author

Felt more productive to share this quick experiment than to simply throw it out. This is just one of many different ways to increase speed (DOM tree would be another I guess).
The live version is here: http://dl.dropbox.com/u/10755342/zipdecode-js/index.html

@NelsonMinar
Copy link
Owner

Hey, I finally had time to look at this code. Thanks so much for contributing it! I'm not going to merge it though, because I chose to improve performance a different way. Your way is actually faster, but the main purpose of this code is a tutorial for D3 and I want to keep it as simple as possible.

FWIW, it turns out the source of slowness in my code was calling .style("fill", ...) on all 40,000 dots. Your code only sets the fill on the dots that are actually changed, which is why it's so much better. The route I took in f5f3f92 was to use .attr("class", ...) on all 40,000 dots to set the colors instead of .style(). Some more discussion here: http://nelsonslog.wordpress.com/2013/03/16/optimizing-zipdecode/

@ZJONSSON
Copy link
Author

I agree that G tree and styles is the most structural way to do this and much better suited for a tutorial.
My code was just a quick hack to get the response time down :) Thanks for the mention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants