perf(ivy): avoid generating extra parameters for host property bindings (#31550)
Currently we reuse the same instruction both for regular property bindings and property bindings on the `host`. The only difference between the two is that when it's on the host we shouldn't support inputs. We have an optional parameter called `nativeOnly` which is used to differentiate the two, however since `nativeOnly` is preceeded by another optional parameter (`sanitizer`), we have to generate two extra parameters for each host property bindings every time (e.g. `property('someProp', 'someValue', null, true)`). These changes add a new instruction called `hostProperty` which avoids the need for the two parameters by removing `nativeOnly` which is always set and it allows us to omit `sanitizer` when it isn't being used. These changes also remove the `nativeOnly` parameter from the `updateSyntheticHostBinding` instruction, because it's only generated for host elements which means that we can assume that its value will always be `true`. PR Close #31550
This commit is contained in:
@ -168,6 +168,8 @@ export class Identifiers {
|
||||
static pipeBind4: o.ExternalReference = {name: 'ɵɵpipeBind4', moduleName: CORE};
|
||||
static pipeBindV: o.ExternalReference = {name: 'ɵɵpipeBindV', moduleName: CORE};
|
||||
|
||||
static hostProperty: o.ExternalReference = {name: 'ɵɵhostProperty', moduleName: CORE};
|
||||
|
||||
static property: o.ExternalReference = {name: 'ɵɵproperty', moduleName: CORE};
|
||||
|
||||
static propertyInterpolate:
|
||||
|
@ -644,7 +644,7 @@ function createHostBindingsFunction(
|
||||
const attributeBindings: o.Expression[][] = [];
|
||||
const syntheticHostBindings: o.Expression[][] = [];
|
||||
|
||||
(bindings || []).forEach((binding: ParsedProperty) => {
|
||||
bindings && bindings.forEach((binding: ParsedProperty) => {
|
||||
const name = binding.name;
|
||||
const stylingInputWasSet =
|
||||
styleBuilder.registerInputBasedOnName(name, binding.expression, binding.sourceSpan);
|
||||
@ -677,18 +677,10 @@ function createHostBindingsFunction(
|
||||
if (sanitizerFn) {
|
||||
instructionParams.push(sanitizerFn);
|
||||
}
|
||||
if (!isAttribute) {
|
||||
if (!sanitizerFn) {
|
||||
// append `null` in front of `nativeOnly` flag if no sanitizer fn defined
|
||||
instructionParams.push(o.literal(null));
|
||||
}
|
||||
// host bindings must have nativeOnly prop set to true
|
||||
instructionParams.push(o.literal(true));
|
||||
}
|
||||
|
||||
updateStatements.push(...bindingExpr.stmts);
|
||||
|
||||
if (instruction === R3.property) {
|
||||
if (instruction === R3.hostProperty) {
|
||||
propertyBindings.push(instructionParams);
|
||||
} else if (instruction === R3.attribute) {
|
||||
attributeBindings.push(instructionParams);
|
||||
@ -701,7 +693,7 @@ function createHostBindingsFunction(
|
||||
});
|
||||
|
||||
if (propertyBindings.length > 0) {
|
||||
updateStatements.push(chainedInstruction(R3.property, propertyBindings).toStmt());
|
||||
updateStatements.push(chainedInstruction(R3.hostProperty, propertyBindings).toStmt());
|
||||
}
|
||||
|
||||
if (attributeBindings.length > 0) {
|
||||
@ -802,7 +794,7 @@ function getBindingNameAndInstruction(binding: ParsedProperty):
|
||||
// compatibility instruction available for this purpose.
|
||||
instruction = R3.updateSyntheticHostBinding;
|
||||
} else {
|
||||
instruction = R3.property;
|
||||
instruction = R3.hostProperty;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user