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

[PERF] make internal model lazier #4562

Merged
merged 1 commit into from Oct 21, 2016

Conversation

runspired
Copy link
Contributor

Branches off of heimdall-instrumentation, so that should be merged fist ;)

@fivetanley
Copy link
Member

so excited 🙏

we'll have to make sure we don't break @BookingSync's and others' addons.

@runspired
Copy link
Contributor Author

@fivetanley this provides identical private API's to what was present before, they are just lazy, with one notable exception. I've removed the use of get and set for currentState. It was being used inconsistently, half the places used dot notation, half used get/set. Looking into the code paths it appears there isn't a strong case for it needing to be get/set based, and obvs with it being inconsistent before if it did "need to be" it would have been broken.

@fivetanley
Copy link
Member

yeah i am not really concerned about the api changing here, just a last step before merging to run it against addons that use internalModel heavily.

@runspired
Copy link
Contributor Author

Also note, the tests on this pass locally but I need to rebase off master for them to pass here, If we could merge heimdall today I've got a follow up PR after this one that's also fun :)

@runspired
Copy link
Contributor Author

@igor rebase complete


// these are here to prevent shape change later when Ember lookups add them
this.__ember_meta__ = null;
this[GUID_KEY] = guidFor(this);
Copy link
Member

Choose a reason for hiding this comment

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

i don't believe the left hand side here is required

changedKeys.push(key);
}
}
}

return changedKeys;
},
}

toString() {
if (this.record) {
return this.record.toString();
Copy link
Member

Choose a reason for hiding this comment

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

this branch seems un-needed

@@ -584,6 +584,7 @@ var RootState = {
},

didCommit(internalModel) {
// TODO @runspired lastDirtyType doesn't seem to be a real thing
internalModel.send('invokeLifecycleCallbacks', get(internalModel, 'lastDirtyType'));
Copy link
Member

Choose a reason for hiding this comment

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

^ todo + get, if its not used then this line may be a candidate for removal

let i;
let l;

if (TransitionChainMap[transitionMapId]) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe let map = TransitionChainMap[transitionMapId] then reference map everywhere

@@ -241,7 +244,7 @@ var DirtyState = {

//TODO(Igor) reloading now triggers a
//loadingData event, though it seems fine?
loadingData: Ember.K,
loadingData: K,
Copy link
Member

Choose a reason for hiding this comment

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

lets just do loadingData() { } rather then the single shared function of K

@@ -4,7 +4,10 @@
import Ember from 'ember';
import { assert } from "ember-data/-private/debug";

var get = Ember.get;
const {
K
Copy link
Member

Choose a reason for hiding this comment

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

lets not use K regular concise functions are likely fine.

@runspired
Copy link
Contributor Author

Eyeballing the production build benchmarks (no filtering of outliers but I am looking at a box plot), we moved from roughly 35ms spent in store.push for 238 records of a single type to a bit less than 28ms.

@tchak
Copy link
Member

tchak commented Oct 18, 2016

LGTM 👍


const assign = Ember.assign || Ember.merge;
const setOwner = Ember.setOwner;
const TransitionChainMap = new EmptyObject();
Copy link
Member

Choose a reason for hiding this comment

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

Can you put a comment here or in the method as to how the transitionchain map works

@runspired runspired force-pushed the feat/internal-model branch 3 times, most recently from 374ea89 to 475d9aa Compare October 19, 2016 10:38
@@ -305,6 +308,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
@private
@type {Object}
*/
currentState: null,
Copy link
Member

Choose a reason for hiding this comment

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

should we define this on the prototype?

@@ -430,7 +433,7 @@ createdState.uncommitted.pushedData = function(internalModel) {
internalModel.triggerLater('didLoad');
};

createdState.uncommitted.propertyWasReset = Ember.K;
createdState.uncommitted.propertyWasReset = K;
Copy link
Member

Choose a reason for hiding this comment

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

= function() { }

@runspired
Copy link
Contributor Author

@igorT Travis is passing after making the changes from @stefanpenner's last review.

- allocations are now lazy
- InternalModel is now an ES2015 class, the expensive classCallCheck is stripped via a babel plugin
- TransitionMapCache has been added to make transitionTo function faster
- get/set of currentState has been moved to dot notation access
- overall this appears to be a 20% perf improvement, with more gains still realizable.
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

5 participants