Skip to content

Commit

Permalink
Avoid scheduleOnce, scourge of good performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jul 29, 2021
1 parent 4f63b12 commit 61a8bce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
16 changes: 7 additions & 9 deletions ember-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10581,6 +10581,7 @@
this.isReloading = false;
this.isError = false;
this.error = null;
this._triggerDeferredTriggersScheduled = false;
/*
implicit relationships are relationship which have not been declared but the inverse side exists on
another record somewhere
Expand Down Expand Up @@ -10934,21 +10935,18 @@
throw new Ember.Error(errorMessage);
},

triggerLater: function () {
var length = arguments.length;
var args = new Array(length);

for (var i = 0; i < length; i++) {
args[i] = arguments[i];
}

triggerLater: function (...args) {
if (this._deferredTriggers.push(args) !== 1) {
return;
}
Ember.run.scheduleOnce('actions', this, '_triggerDeferredTriggers');
if (!this._triggerDeferredTriggersScheduled) {
this._triggerDeferredTriggersScheduled = true;
Ember.run.schedule('actions', this, '_triggerDeferredTriggers');
}
},

_triggerDeferredTriggers: function () {
this._triggerDeferredTriggersScheduled = false;
//TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record,
//but for now, we queue up all the events triggered before the record was materialized, and flush
//them once we have the record
Expand Down
16 changes: 7 additions & 9 deletions ember-data.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10386,6 +10386,7 @@
this.isReloading = false;
this.isError = false;
this.error = null;
this._triggerDeferredTriggersScheduled = false;
/*
implicit relationships are relationship which have not been declared but the inverse side exists on
another record somewhere
Expand Down Expand Up @@ -10738,21 +10739,18 @@
throw new Ember.Error(errorMessage);
},

triggerLater: function () {
var length = arguments.length;
var args = new Array(length);

for (var i = 0; i < length; i++) {
args[i] = arguments[i];
}

triggerLater: function (...args) {
if (this._deferredTriggers.push(args) !== 1) {
return;
}
Ember.run.scheduleOnce('actions', this, '_triggerDeferredTriggers');
if (!this._triggerDeferredTriggersScheduled) {
this._triggerDeferredTriggersScheduled = true;
Ember.run.schedule('actions', this, '_triggerDeferredTriggers');
}
},

_triggerDeferredTriggers: function () {
this._triggerDeferredTriggersScheduled = false;
//TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record,
//but for now, we queue up all the events triggered before the record was materialized, and flush
//them once we have the record
Expand Down

0 comments on commit 61a8bce

Please sign in to comment.