From 66b87cef33674ac42362417066db4ecf83379dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 28 Mar 2019 15:51:33 -0700 Subject: [PATCH] fix(ivy): add dev mode counter information to styling (#29579) In order to optimize performance for styling-related operations in Angular, debug counters need to be introduced. This patch adds various counters to ngDevMode which are fired each time a styling-related binding is updated. PR Close #29579 --- .../src/render3/styling/class_and_style_bindings.ts | 10 ++++++++++ packages/core/src/util/ng_dev_mode.ts | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/core/src/render3/styling/class_and_style_bindings.ts b/packages/core/src/render3/styling/class_and_style_bindings.ts index 59d13727c3..81146f79ee 100644 --- a/packages/core/src/render3/styling/class_and_style_bindings.ts +++ b/packages/core/src/render3/styling/class_and_style_bindings.ts @@ -514,6 +514,7 @@ export function updateStylingMap( BoundPlayerFactory| null, stylesInput?: {[key: string]: any} | BoundPlayerFactory| null, directiveIndex: number = 0): void { + ngDevMode && ngDevMode.stylingMap++; ngDevMode && assertValidDirectiveIndex(context, directiveIndex); classesInput = classesInput || null; stylesInput = stylesInput || null; @@ -600,6 +601,8 @@ export function updateStylingMap( if (playerBuildersAreDirty) { setContextPlayersDirty(context, true); } + + ngDevMode && ngDevMode.stylingMapCacheMiss++; } /** @@ -904,6 +907,8 @@ function updateSingleStylingValue( const currDirective = getDirectiveIndexFromEntry(context, singleIndex); const value: string|boolean|null = (input instanceof BoundPlayerFactory) ? input.value : input; + ngDevMode && ngDevMode.stylingProp++; + if (hasValueChanged(currFlag, currValue, value) && (forceOverride || allowValueChange(currValue, value, currDirective, directiveIndex))) { const isClassBased = (currFlag & StylingFlags.Class) === StylingFlags.Class; @@ -958,6 +963,8 @@ function updateSingleStylingValue( if (playerBuildersAreDirty) { setContextPlayersDirty(context, true); } + + ngDevMode && ngDevMode.stylingPropCacheMiss++; } } @@ -986,6 +993,7 @@ export function renderStyling( isFirstRender: boolean, classesStore?: BindingStore | null, stylesStore?: BindingStore | null, directiveIndex: number = 0): number { let totalPlayersQueued = 0; + ngDevMode && ngDevMode.stylingApply++; // this prevents multiple attempts to render style/class values on // the same element... @@ -1000,6 +1008,8 @@ export function renderStyling( flushHostInstructionsQueue(context); if (isContextDirty(context)) { + ngDevMode && ngDevMode.stylingApplyCacheMiss++; + // this is here to prevent things like ... // or if there are any host style or class bindings present in a directive set on // a container node diff --git a/packages/core/src/util/ng_dev_mode.ts b/packages/core/src/util/ng_dev_mode.ts index 9606a94ce0..4444881395 100644 --- a/packages/core/src/util/ng_dev_mode.ts +++ b/packages/core/src/util/ng_dev_mode.ts @@ -29,6 +29,12 @@ declare global { rendererMoveNode: number; rendererRemoveNode: number; rendererCreateComment: number; + stylingMap: number; + stylingMapCacheMiss: number; + stylingProp: number; + stylingPropCacheMiss: number; + stylingApply: number; + stylingApplyCacheMiss: number; } } @@ -56,6 +62,12 @@ export function ngDevModeResetPerfCounters(): NgDevModePerfCounters { rendererMoveNode: 0, rendererRemoveNode: 0, rendererCreateComment: 0, + stylingMap: 0, + stylingMapCacheMiss: 0, + stylingProp: 0, + stylingPropCacheMiss: 0, + stylingApply: 0, + stylingApplyCacheMiss: 0, }; // NOTE: Under Ivy we may have both window & global defined in the Node // environment since ensureDocument() in render3.ts sets global.window.