-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Faster Collection _reset #2106
Faster Collection _reset #2106
Conversation
Wow! It's much faster! I didn't know the performance tip. I've been thinking that |
👍 Looks good to me |
Good stuff. Thanks @akre54! |
@akre54 Unfortunately your test is flawed. The results seemed a little too good to be true, so I traced exactly what was happening. You are creating models from only the most recently loaded Here is a more fair test comparing just before your changes to afterward: http://jsperf.com/bb-faster-array-reset/2 |
Ahh damn. Good catch! I knew that big of a jump seemed usual. Moral of the story: don't use Backbone Models? 😀 I copied the Events test setup from http://jsperf.com/events-vs-events2, and didn't consider the knock-on effects from models, thanks for tracking it down. I'll try and dive a little deeper next time. |
This appears to be breaking Backbone.Paginator (ClientPager specifically) on Chrome 25.0.1364.29 beta and Firefox 17. I'll run some more tests and post a test case |
@caseywebdev feel free to revert. no sense in keeping broken code around. P.S. want to look into closing #2104? |
@caseywebdev - don't worry about reverting this one just yet. It's actually an issue with #2003 - |
Slow down a bit folks -- please don't merge stuff like this ;) Looking at the diff, it confuses and tangles the logic of the code a little bit. And as was discovered later, the micro-benchmark was totally spurious (as micro-benchmarks often are). Unless it's in the hottest of hot loops, there's not going to be a place in Backbone where truncating and reusing an array with I'll revert. |
@jashkenas in their defense (and mine) it was a pretty hot speed boost (50x in best case). It was only due to the detective work by Casey that it was clear this improvement was in error. Definitely agreed about making code look uglier. |
Certainly -- and no worries, I appreciate it. The point I'm trying to make is just that we've been burned in Backbone many times in the past by compelling-looking JSPerf tests that don't actually have a meaningful effect on an application's performance. Even if it is a 50x speed up for a particular little piece, that little piece may not have a noticeable effect, or a meaningless one at runtime. For example, imagine you optimized the |
Yep, paginator broken on v0.9.10: http://jsfiddle.net/webxl/7pSx5/ Looks like it's fixed on master now: http://jsfiddle.net/webxl/nJbHF/ Thanks! |
So, the issue is caused by the fact that |
As discovered in #2098, resetting Collection#models with an empty array is slow and prone to memory leaks (see SO post).
Setting
this.models.length = 0
shows a manifold (up to about 50x) improvement over master: jsperf