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.
|
||||
*
|
||||
* 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
|
||||
* type-checking machinery of ngtsc.
|
||||
*/
|
||||
const ATTR_TO_PROP: {[name: string]: string} = {
|
||||
'class': 'className',
|
||||
'for': 'htmlFor',
|
||||
'formaction': 'formAction',
|
||||
'innerHtml': 'innerHTML',
|
||||
'readonly': 'readOnly',
|
||||
'tabindex': 'tabIndex',
|
||||
};
|
||||
function mapPropName(name: string): string {
|
||||
if (name === 'class') return 'className';
|
||||
if (name === 'for') return 'htmlFor';
|
||||
if (name === 'formaction') return 'formAction';
|
||||
if (name === 'innerHtml') return 'innerHTML';
|
||||
if (name === 'readonly') return 'readOnly';
|
||||
if (name === 'tabindex') return 'tabIndex';
|
||||
return name;
|
||||
}
|
||||
|
||||
export function elementPropertyInternal<T>(
|
||||
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) {
|
||||
propName = ATTR_TO_PROP[propName] || propName;
|
||||
propName = mapPropName(propName);
|
||||
|
||||
if (ngDevMode) {
|
||||
validateAgainstEventProperties(propName);
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
{
|
||||
"name": "ANIMATION_PROP_PREFIX"
|
||||
},
|
||||
{
|
||||
"name": "ATTR_TO_PROP"
|
||||
},
|
||||
{
|
||||
"name": "BINDING_INDEX"
|
||||
},
|
||||
|
@ -1085,6 +1082,9 @@
|
|||
{
|
||||
"name": "makeParamDecorator"
|
||||
},
|
||||
{
|
||||
"name": "mapPropName"
|
||||
},
|
||||
{
|
||||
"name": "markAsComponentHost"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue