-
-
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
Improve performance using array instead of linked-list to implement Backbone.Events #1284
Conversation
It was originally changed from an array implementation to a linked list implementation for performance reasons. Mind taking a look at the original ticket, and letting me know what you think? |
@jashkenas Thanks for your information, I found this ticket: And the source code of the array implementation before the linked list version is: This array implementation has some "ugly" code to affect performance, such as:
In my array implementation, I have deal with carefully to fix all the performance issues. A updated performance comparision: http://jsperf.com/backbone-events-linked-list/8 It seems that the new array-implementation is very faster than the current linked-list version. And more important, the array implementation is more readability than the linked-list version. I think it is worthy coming back to the array implementation with performance improving. |
This is fantastic stuff @lifesinger! Sorry about the original request. I shouldn't have been so quick to close it. :) I think the huge discrepancies in Chrome and Firefox are due to their copy-on-write array implementations. In the vast majority of cases the callback list won't be altered during |
Improve performance using array instead of linked-list to implement Backbone.Events
@braddunbar It is very happy to see this merge. Except copy-on-write array implementations in chrome and firefox, another notable performance improving is: changing
to
In most cases, the Hope that Backbone is getting better and better. |
Agreed. I was rather surprised that |
[js perf](http://jsperf.com/backbone-events-linked-list/18) Roughly equivalent performance. Using a linked list allows the events to be mutated by trigger, without skipping an event. This is a **breaking change**. Events used to use a linked list (and switched to an array in jashkenas#1284). But, it performed [very badly](http://jsperf.com/backbone-events-linked-list/8). I'm fairly certain that was due to [L106](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L106) recreating the linked list's object every `#on`, and [L138](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L138) calling `#on` to re-bind callbacks. This fixes jashkenas#3466 and closes jashkenas#3463.
[js perf](http://jsperf.com/backbone-events-linked-list/18) Roughly equivalent performance. Using a linked list allows the events to be mutated by trigger, without skipping an event. This is a **breaking change**. Events used to use a linked list (and switched to an array in jashkenas#1284). But, it performed [very badly](http://jsperf.com/backbone-events-linked-list/8). I'm fairly certain that was due to [L106](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L106) recreating the linked list's object every `#on`, and [L138](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L138) calling `#on` to re-bind callbacks inside `#off`. This fixes jashkenas#3466 and closes jashkenas#3463.
[js perf](http://jsperf.com/backbone-events-linked-list/18) Roughly equivalent performance. Using a linked list allows the events to be mutated by trigger, without skipping an event. This is a **breaking change**. Events used to use a linked list (and switched to an array in jashkenas#1284). But, it performed [very badly](http://jsperf.com/backbone-events-linked-list/8). I'm fairly certain that was due to [L106](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L106) recreating the linked list's object every `#on`, and [L138](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L138) calling `#on` to re-bind callbacks inside `#off`. This fixes jashkenas#3466 and closes jashkenas#3463.
[js perf](http://jsperf.com/backbone-events-linked-list/18) Roughly equivalent performance. Using a linked list allows the events to be mutated by trigger, without skipping an event. This is a **breaking change**. Events used to use a linked list (and switched to an array in jashkenas#1284). But, it performed [very badly](http://jsperf.com/backbone-events-linked-list/8). I'm fairly certain that was due to [L106](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L106) recreating the linked list's object every `#on`, and [L138](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L138) calling `#on` to re-bind callbacks inside `#off`. This fixes jashkenas#3466 and closes jashkenas#3463.
[js perf](http://jsperf.com/backbone-events-linked-list/18) Roughly equivalent performance. Using a linked list allows the events to be mutated by trigger, without skipping an event. This is a **breaking change**. Events used to use a linked list (and switched to an array in jashkenas#1284). But, it performed [very badly](http://jsperf.com/backbone-events-linked-list/8). I'm fairly certain that was due to [L106](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L106) recreating the linked list's object every `#on`, and [L138](https://github.com/jashkenas/backbone/blob/6c3d3838e10d5a070f0d1f604fb5c99ed34c8c93/backbone.js#L138) calling `#on` to re-bind callbacks inside `#off`. This fixes jashkenas#3466 and closes jashkenas#3463.
In Chrome 18:
http://jsperf.com/backbone-events-linked-list/8
Maybe it is worthy to merge this pull request.