Skip to content

Commit

Permalink
Add hasPaths optimziation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Mar 5, 2019
1 parent 9ed3189 commit ef0efa6
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,21 @@ const TRANSITIVE_DEPENDENCY = '~transitive~dependency~';
* @param {?Object} changedProps Bag of current property changes
* @param {?Object} oldProps Bag of previous values for changed properties
* @param {?} info Effect metadata
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
* @return {void}
* @private
*/
function runComputedEffect(inst, property, changedProps, oldProps, info) {
function runComputedEffect(inst, property, changedProps, oldProps, info, hasPaths) {
if (orderedComputed) {
// Compute any computed dependencies first; this recurses through the
// dependency graph to ensure computed properties are never computed with
// dependencies that may become invalidated later in this turn
computeDependencies(inst, info, changedProps, oldProps);
computeDependencies(inst, info, changedProps, oldProps, hasPaths);
// If the dependency was not transitive, it's definitely dirty and needs to
// be computed; if it is transitive, check its arguments against the current
// changed props and only re-compute if it is dirty
if (property === TRANSITIVE_DEPENDENCY &&
!computedPropertyIsDirty(inst, info, changedProps)) {
!computedPropertyIsDirty(inst, info, changedProps, hasPaths)) {
return;
}
}
Expand Down Expand Up @@ -502,16 +503,17 @@ function runComputedEffect(inst, property, changedProps, oldProps, info) {
* @param {Object} info Effect metadata
* @param {Object} changedProps Bag of current property changes
* @param {Object} oldProps Bag of previous values for changed properties
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
* @return {void}
* @private
*/
function computeDependencies(inst, info, changedProps, oldProps) {
function computeDependencies(inst, info, changedProps, oldProps, hasPaths) {
let deps = computedDependenciesFor(inst, info);
if (deps.length) {
deps.forEach(depInfo => {
if (depInfo.lastRun !== info.lastRun) {
depInfo.lastRun = info.lastRun;
runComputedEffect(inst, TRANSITIVE_DEPENDENCY, changedProps, oldProps, depInfo);
runComputedEffect(inst, TRANSITIVE_DEPENDENCY, changedProps, oldProps, depInfo, hasPaths);
}
});
}
Expand All @@ -523,12 +525,13 @@ function runComputedEffect(inst, property, changedProps, oldProps, info) {
* @param {!Polymer_PropertyEffects} inst The instance to test
* @param {?} info Effect metadata
* @param {Object} changedProps Bag of current property changes
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
* @return {boolean} true when the computed effect should be re-calculated
* @private
*/
function computedPropertyIsDirty(inst, info, changedProps) {
return info.dynamicFn && propertyIsDirty(inst, {name: info.methodName}, changedProps) ||
info.args.some(arg => propertyIsDirty(inst, arg, changedProps));
function computedPropertyIsDirty(inst, info, changedProps, hasPaths) {
return info.dynamicFn && propertyIsDirty(inst, {rootProperty: info.methodName}, changedProps, hasPaths) ||
info.args.some(arg => propertyIsDirty(inst, arg, changedProps, hasPaths));
}

/**
Expand All @@ -537,17 +540,23 @@ function computedPropertyIsDirty(inst, info, changedProps) {
* @param {!Polymer_PropertyEffects} inst The instance to test
* @param {DataTrigger} trigger Descriptor
* @param {Object} changedProps Bag of current property changes
* @param {boolean} hasPaths True with `changedProps` contains one or more paths
* @return {boolean} true when the property is dirty
* @private
*/
function propertyIsDirty(inst, trigger, changedProps) {
return [changedProps, inst.__dataPending].some(props => {
for (let p in props) {
if (pathMatchesTrigger(p, trigger)) {
return true;
function propertyIsDirty(inst, trigger, changedProps, hasPaths) {
if (hasPaths) {
[changedProps, inst.__dataPending].some(props => {
for (let p in props) {
if (pathMatchesTrigger(p, trigger)) {
return true;
}
}
}
});
});
} else {
return changedProps && trigger.rootProperty in changedProps ||
inst.__dataPending && trigger.rootProperty in inst.__dataPending;
}
}

/**
Expand Down

0 comments on commit ef0efa6

Please sign in to comment.