perf(ivy): avoid megamorphic reads during property binding (#32574)
While determining a property name to bind to we were checking a mapping object resulting in the megamorphic read. Replacing such read with a series of if checks speeds up rproprty update benchmark ~30% (~1400ms down to ~1000ms). PR Close #32574
This commit is contained in:
parent
ea378a993a
commit
fcdd06896e
|
@ -840,17 +840,23 @@ export function generatePropertyAliases(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping between attributes names that don't correspond to their element property names.
|
* Mapping between attributes names that don't correspond to their element property names.
|
||||||
|
*
|
||||||
|
* Performance note: this function is written as a series of if checks (instead of, say, a property
|
||||||
|
* object lookup) for performance reasons - the series of `if` checks seems to be the fastest way of
|
||||||
|
* mapping property names. Do NOT change without benchmarking.
|
||||||
|
*
|
||||||
* Note: this mapping has to be kept in sync with the equally named mapping in the template
|
* Note: this mapping has to be kept in sync with the equally named mapping in the template
|
||||||
* type-checking machinery of ngtsc.
|
* type-checking machinery of ngtsc.
|
||||||
*/
|
*/
|
||||||
const ATTR_TO_PROP: {[name: string]: string} = {
|
function mapPropName(name: string): string {
|
||||||
'class': 'className',
|
if (name === 'class') return 'className';
|
||||||
'for': 'htmlFor',
|
if (name === 'for') return 'htmlFor';
|
||||||
'formaction': 'formAction',
|
if (name === 'formaction') return 'formAction';
|
||||||
'innerHtml': 'innerHTML',
|
if (name === 'innerHtml') return 'innerHTML';
|
||||||
'readonly': 'readOnly',
|
if (name === 'readonly') return 'readOnly';
|
||||||
'tabindex': 'tabIndex',
|
if (name === 'tabindex') return 'tabIndex';
|
||||||
};
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
export function elementPropertyInternal<T>(
|
export function elementPropertyInternal<T>(
|
||||||
index: number, propName: string, value: T, sanitizer?: SanitizerFn | null, nativeOnly?: boolean,
|
index: number, propName: string, value: T, sanitizer?: SanitizerFn | null, nativeOnly?: boolean,
|
||||||
|
@ -883,7 +889,7 @@ export function elementPropertyInternal<T>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (tNode.type === TNodeType.Element) {
|
} else if (tNode.type === TNodeType.Element) {
|
||||||
propName = ATTR_TO_PROP[propName] || propName;
|
propName = mapPropName(propName);
|
||||||
|
|
||||||
if (ngDevMode) {
|
if (ngDevMode) {
|
||||||
validateAgainstEventProperties(propName);
|
validateAgainstEventProperties(propName);
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
{
|
{
|
||||||
"name": "ANIMATION_PROP_PREFIX"
|
"name": "ANIMATION_PROP_PREFIX"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "ATTR_TO_PROP"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "BINDING_INDEX"
|
"name": "BINDING_INDEX"
|
||||||
},
|
},
|
||||||
|
@ -1085,6 +1082,9 @@
|
||||||
{
|
{
|
||||||
"name": "makeParamDecorator"
|
"name": "makeParamDecorator"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "mapPropName"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "markAsComponentHost"
|
"name": "markAsComponentHost"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue