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

complex InternalModel attributes may want to become lazy #3644

Closed
stefanpenner opened this issue Aug 12, 2015 · 2 comments
Closed

complex InternalModel attributes may want to become lazy #3644

stefanpenner opened this issue Aug 12, 2015 · 2 comments
Labels
🏷️ perf PRs that improve performance in a notable way

Comments

@stefanpenner
Copy link
Member Author

some more details.

currently we have:

export default function InternalModel(type, id, store, container, data) {
  // ...
  this._data = data || new EmptyObject();
  this._attributes = new EmptyObject();
  this._deferredTriggers = [];
  this._attributes = new EmptyObject();
  this._inFlightAttributes = new EmptyObject();
  this._relationships = new Relationships(this);
  //..
}

If for complex attributes that not every InternalModel uses upfront, we made them lazy.

First step, shape the object:

export default function InternalModel(type, id, store, container, data) {
  // ...
  this._data = data || undefined;
  this._attributes = undefined;
  this._deferredTriggers = undefined;
  this._attributes = undefined;
  this._inFlightAttributes = undefined;
  this._relationships = undefined;
  //..
}

then make accessors for each property, something like that.

InternalModel.prototype.getData = function() {
  if (this._data) { return this._data;}
  return (this._data = new EmptyObject());
};

Then update internal usage accordingly.

We can mitigate unused early allocations.


*note: it may also be worth experimenting with es5 accessors directly (newer runtimes do optimize them correctly - we should confirm our target browsers all do, but doing it without would allow these changes to be backportable)

@pangratz
Copy link
Member

Closing due to the work done by @runspired in #4562 🚀

@runspired runspired added performance 🏷️ perf PRs that improve performance in a notable way and removed perf labels Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ perf PRs that improve performance in a notable way
Projects
None yet
Development

No branches or pull requests

3 participants