perf(ivy): avoid memory allocation in the isAnimationProp check (#32997)

Accessing a string's character at index allocates a new, single character string.
A better (faster) check is to use `charCodeAt` that doesn't trigger allocation.

This simple change speeds up the element_text_create benchmark by ~7%.

PR Close #32997
This commit is contained in:
Pawel Kozlowski
2019-10-04 12:13:25 +02:00
committed by Alex Rickabaugh
parent affae99b22
commit 9f0c549bc8
4 changed files with 6 additions and 12 deletions

View File

@ -100,8 +100,9 @@ export function isNameOnlyAttributeMarker(marker: string | AttributeMarker | Css
marker === AttributeMarker.I18n;
}
export const ANIMATION_PROP_PREFIX = '@';
export function isAnimationProp(name: string): boolean {
return name[0] === ANIMATION_PROP_PREFIX;
// Perf note: accessing charCodeAt to check for the first character of a string is faster as
// compared to accessing a character at index 0 (ex. name[0]). The main reason for this is that
// charCodeAt doesn't allocate memory to return a substring.
return name.charCodeAt(0) === 64; // @
}