canjs / can-stache-key

Support for reading and writing to keys.
https://www.npmjs.com/package/can-stache-key
MIT License
1 stars 0 forks source link

Performance optimization #47

Open pYr0x opened 5 years ago

pYr0x commented 5 years ago

very time can-stache-key reads from object in line 239 (https://github.com/canjs/can-stache-key/blob/77cd4802a6a31b18835c30305ccb3c1f94c1f68b/can-stache-key.js#L239) we check the whole object included the prototype, which we dont need (i think). by doing this thousand of time this slow down. i would recommend to replace this line into if(value.hasOwnProperty(prop.key)) {

@phillipskevin @justinbmeyer

phillipskevin commented 5 years ago

I think this would break some things since we set some properties on Scope.prototype:

https://github.com/canjs/can-view-scope/blob/ae105e5b52e8008427ed9687c53fbb6ae552c38c/can-view-scope.js#L973-L1039

So things like scope.vm.foo wouldn't work because scope.hasOwnProperty("vm") would be false.

pYr0x commented 5 years ago

Ok... good point

What if we check first with hasOwnProperty and if we didn’t found the key we check in a for-loop that’s special keys?

But how can we get this keys form can-view-scope into can-stache-key?

phillipskevin commented 5 years ago

What if we check first with hasOwnProperty and if we didn’t found the key we check in a for-loop that’s special keys?

You mean if it isn't an own property, just check if it is one of the special properties added by can-view-scope?

pYr0x commented 5 years ago

yep ;), but how do we get these special properties form can-view-scope

justinbmeyer commented 5 years ago

Can you share a performance profile related to this?

justinbmeyer commented 5 years ago

btw, we need that b/c functions are almost always on the prototype.