From a77d0e22bf82582c036cf5a936185f471b5dce53 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 24 Jul 2019 16:12:20 +0200 Subject: [PATCH] perf(ivy): avoid repeated tView.firstTemplatePass writes (#31839) PR Close #31839 --- packages/core/src/render3/instructions/shared.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index b9fec7ed51..a59b643d7b 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -63,7 +63,11 @@ export function refreshDescendantViews(lView: LView) { const tView = lView[TVIEW]; const creationMode = isCreationMode(lView); - // This needs to be set before children are processed to support recursive components + // This needs to be set before children are processed to support recursive components. + // This must be set to false immediately after the first creation run because in an + // ngFor loop, all the views will be created together before update mode runs and turns + // off firstTemplatePass. If we don't set it here, instances will perform directive + // matching, etc again and again. tView.firstTemplatePass = false; // Resetting the bindingIndex of the current LView as the next steps may trigger change detection. @@ -413,13 +417,6 @@ export function renderEmbeddedTemplate(viewToRender: LView, tView: TView, con oldView = enterView(viewToRender, viewToRender[T_HOST]); resetPreOrderHookFlags(viewToRender); executeTemplate(viewToRender, tView.template !, getRenderFlags(viewToRender), context); - - // This must be set to false immediately after the first creation run because in an - // ngFor loop, all the views will be created together before update mode runs and turns - // off firstTemplatePass. If we don't set it here, instances will perform directive - // matching, etc again and again. - tView.firstTemplatePass = false; - refreshDescendantViews(viewToRender); safeToRunHooks = true; } finally {