From ce9419220b958bc3d0a419075c22552933e693df Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 7 Dec 2019 22:36:06 +0100 Subject: [PATCH] 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 --- packages/compiler/src/render3/view/template.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index 4d1543f6b2..a6fcf5eb08 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -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) {