From 2c4a2f51582997d141c35da77e68f7205e892035 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 4 Dec 2014 14:23:23 +0100 Subject: [PATCH] perf(Change Detection): Track the range & group on changes only 1.4x speed improvement with Firefox There is no need to track the range & group for all the records but only for the records that have changed. --- modules/change_detection/src/change_detector.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/change_detection/src/change_detector.js b/modules/change_detection/src/change_detector.js index 058defcdca..79a3baa392 100644 --- a/modules/change_detection/src/change_detector.js +++ b/modules/change_detection/src/change_detector.js @@ -17,24 +17,23 @@ export class ChangeDetector { var count = 0; var updatedRecords = null; var record = this._rootRecordRange.findFirstEnabledRecord(); + var currentRange, currentGroup; while (isPresent(record)) { - var currentRange = record.recordRange; - var currentGroup = record.groupMemento(); - if (record.check()) { count++; if (record.terminatesExpression()) { + currentRange = record.recordRange; + currentGroup = record.groupMemento(); updatedRecords = this._addRecord(updatedRecords, record); } } if (isPresent(updatedRecords)) { var nextEnabled = record.nextEnabled; - var nextRange = isPresent(nextEnabled) ? nextEnabled.recordRange : null; - var nextGroup = isPresent(nextEnabled) ? nextEnabled.groupMemento() : null; - - if (currentRange != nextRange || currentGroup != nextGroup) { + if (isBlank(nextEnabled) || // we have reached the last enabled record + currentRange != nextEnabled.recordRange || // the next record is in a different range + currentGroup != nextEnabled.groupMemento()) { // the next record is in a different group currentRange.dispatcher.onRecordChange(currentGroup, updatedRecords); updatedRecords = null; }