Skip to content
Permalink
Browse files

perf(ivy): improve NaN checks in change detection (#32212)

This commit drops our custom, change-detection specific, equality comparison util
in favour of the standard Object.is which has desired semantics.

There are multiple advantages of this approach:
- less code to maintain on our end;
- avoid NaN checks if both values are equal;
- re-write NaN checks so we don't trigger V8 deoptimizations.

PR Close #32212
  • Loading branch information...
pkozlowski-opensource authored and AndrewKushnir committed Aug 20, 2019
1 parent 53f33c1 commit 53bfa7c6d60b2fd9e51eeb433a827096ae8f834e
@@ -12,8 +12,6 @@ import {throwErrorIfNoChangesMode} from './errors';
import {LView} from './interfaces/view';
import {getCheckNoChangesMode} from './state';
import {NO_CHANGE} from './tokens';
import {isDifferent} from './util/misc_utils';



// TODO(misko): consider inlining
@@ -36,9 +34,11 @@ export function bindingUpdated(lView: LView, bindingIndex: number, value: any):
ngDevMode && assertNotSame(value, NO_CHANGE, 'Incoming value should never be NO_CHANGE.');
ngDevMode &&
assertLessThan(bindingIndex, lView.length, `Slot should have been initialized to NO_CHANGE`);

const oldValue = lView[bindingIndex];
if (isDifferent(oldValue, value)) {

if (Object.is(oldValue, value)) {
return false;
} else {
if (ngDevMode && getCheckNoChangesMode()) {
// View engine didn't report undefined values as changed on the first checkNoChanges pass
// (before the change detection was run).
@@ -50,8 +50,6 @@ export function bindingUpdated(lView: LView, bindingIndex: number, value: any):
lView[bindingIndex] = value;
return true;
}

return false;
}

/** Updates 2 bindings if changed, then returns whether either was updated. */
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {TNode, TNodeFlags} from '../interfaces/node';
import {isDifferent} from '../util/misc_utils';

import {StylingMapArray, StylingMapArrayIndex, TStylingConfigFlags, TStylingContext, TStylingContextIndex, TStylingContextPropConfigFlags} from './interfaces';

@@ -160,7 +159,7 @@ export function hasValueChanged(
if (compareValueB instanceof String) {
compareValueB = compareValueB.toString();
}
return isDifferent(compareValueA, compareValueB);
return !Object.is(compareValueA, compareValueB);
}

/**
@@ -8,18 +8,6 @@

import {global} from '../../util/global';
import {RElement} from '../interfaces/renderer';
import {NO_CHANGE} from '../tokens';

/**
* Returns whether the values are different from a change detection stand point.
*
* Constraints are relaxed in checkNoChanges mode. See `devModeEqual` for details.
*/
export function isDifferent(a: any, b: any): boolean {
// NaN is the only value that is not equal to itself so the first
// test checks if both a and b are not NaN
return !(a !== a && b !== b) && a !== b;
}

/**
* Used for stringify render output in Ivy.
@@ -1010,9 +1010,6 @@
{
"name": "isDevMode"
},
{
"name": "isDifferent"
},
{
"name": "isFactory"
},

This file was deleted.

0 comments on commit 53bfa7c

Please sign in to comment.
You can’t perform that action at this time.