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

improve performance of Ember.guidFor and Ember.generateGuide on #4158

Merged

Conversation

stefanpenner
Copy link
Member

Ember.Objects

Ember's guidKey uses defineProperty so that it is not enumerable,
this is a great idea, but can cost be a hard hit. Luckily though,
we pre-shape all ember objects to have a GUID_KEY slot. Unfortunately,
in guidFor and generateGuid we redefine the property. Not only is this
wasteful, but Object.defineProperty is incredibly costly.

Some micro-benchmarks:

more to come.

The cost of guidFor is about 5 - 10 times faster on Ember.Objects, and can still be improved.

// super scientific quick test.
var pool = []; for(var i =0; i < 10000; i++) { pool.push(Ember.Object.create()); }

console.time('guid');

for (var p = 0; p < pool.length; p++) {
  Ember.guidFor(pool[p]);
}

console.timeEnd('guid');

and the cost to Object.create seems essentially 0. Their is a slight memory usage increase for never guid'd Ember.Object's as they store their guid Number.

If we continue to need guid's I wonder if we should always store them merely as the integer value.

related, @ebryn is working on some directions which mitigate the need for defineProperty on some objects (like views). If we can drop these safely across the board it would be a large win.

@stefanpenner
Copy link
Member Author

@ebryn pointed out this has some safety issues with pojos.

@@ -37,6 +37,15 @@ test("Object with prototype", function() {
diffGuid( a, b, "after calling rewatch, objects don't share guids" );
});

test("Object with Ember.create", function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is the POJO safety issue @ebryn pointed out, we may want to ensure this makes it back into master, even if this experiment does not.

[EDIT] as it turns out this thing we thought was a break, is actually how it always was..

@stefanpenner
Copy link
Member Author

this only improves first-guid of an object, we can still improve more.

Ember.Objects

Ember's guidKey uses defineProperty so that it is not enumerable,
this is a great idea, but can cost be a hard hit. Luckily though,
we pre-shape all ember objects to have a GUID_KEY slot. Unfortunately,
in guidFor and generateGuid we redefine the property. Not only is this
wasteful, but Object.defineProperty is incredibly costly.
krisselden added a commit that referenced this pull request Jan 16, 2014
…d-for

improve performance of Ember.guidFor and Ember.generateGuide on
@krisselden krisselden merged commit 51c6af6 into emberjs:master Jan 16, 2014
@stefanpenner stefanpenner deleted the improve-performance-of-guid-for branch January 16, 2014 23:30
@lukemelia
Copy link
Member

Nice!

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.

3 participants