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

Property binding perf improvements #32212

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/core/src/render3/bindings.ts
Expand Up @@ -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
Expand All @@ -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).
Expand All @@ -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. */
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/render3/instructions/property.ts
Expand Up @@ -5,7 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {assertNotEqual} from '../../util/assert';
import {bindingUpdated} from '../bindings';
import {SanitizerFn} from '../interfaces/sanitization';
import {BINDING_INDEX, LView} from '../interfaces/view';
Expand Down Expand Up @@ -35,12 +34,10 @@ import {TsickleIssue1009, elementPropertyInternal, storeBindingMetadata} from '.
*/
export function ɵɵproperty<T>(
propName: string, value: T, sanitizer?: SanitizerFn | null): TsickleIssue1009 {
const index = getSelectedIndex();
ngDevMode && assertNotEqual(index, -1, 'selected index cannot be -1');
const lView = getLView();
const bindReconciledValue = bind(lView, value);
if (bindReconciledValue !== NO_CHANGE) {
elementPropertyInternal(index, propName, bindReconciledValue, sanitizer);
elementPropertyInternal(getSelectedIndex(), propName, bindReconciledValue, sanitizer);
}
return ɵɵproperty;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/render3/styling_next/util.ts
Expand Up @@ -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';

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

/**
Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/render3/util/misc_utils.ts
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Expand Up @@ -1007,9 +1007,6 @@
{
"name": "isDevMode"
},
{
"name": "isDifferent"
},
{
"name": "isFactory"
},
Expand Down
68 changes: 0 additions & 68 deletions packages/core/test/render3/util_spec.ts

This file was deleted.