perf(ivy): share instances of `DomElementSchemaRegistry` (#34332)

To create a binding parser, an instance of `ElementSchemaRegistry` is
required. Prior to this change, each time a new binding parser was
created a new instance of `DomElementSchemaRegistry` would be
instantiated. This is an expensive operation that takes roughly 1ms per
instantiation, so it is key that multiple allocations are avoided.

By sharing a single `DomElementSchemaRegistry`, we avoid two such
allocations, i.e. save ~2ms, per component template.

PR Close #34332
This commit is contained in:
JoostK 2019-12-07 22:36:06 +01:00 committed by Kara Erickson
parent 3255d2b197
commit 6e5f076330
1 changed files with 3 additions and 2 deletions

View File

@ -2014,13 +2014,14 @@ export function parseTemplate(
return {nodes, styleUrls, styles};
}
const elementRegistry = new DomElementSchemaRegistry();
/**
* Construct a `BindingParser` with a default configuration.
*/
export function makeBindingParser(
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): BindingParser {
return new BindingParser(
new Parser(new Lexer()), interpolationConfig, new DomElementSchemaRegistry(), null, []);
return new BindingParser(new Parser(new Lexer()), interpolationConfig, elementRegistry, null, []);
}
export function resolveSanitizationFn(context: core.SecurityContext, isAttribute?: boolean) {