From 80dbd74ae8dcf72f4f0b99ad4fe98e5dce2be04e Mon Sep 17 00:00:00 2001 From: arturovt Date: Mon, 8 Dec 2025 23:37:28 +0200 Subject: [PATCH] refactor(core): wrap operationsCounter calls with ngDevMode checks Wrap operationsCounter method calls (recordCreate, recordDestroy, reset) with ngDevMode guards to ensure they are tree-shaken in production builds. This aligns with the existing pattern where operationsCounter is only initialized in development mode, and eliminates unnecessary method call overhead in production. The optional chaining (?.) is retained as TypeScript doesn't narrow types based on ngDevMode checks, but the entire expression will be removed during production builds. --- packages/core/src/render3/instructions/control_flow.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/render3/instructions/control_flow.ts b/packages/core/src/render3/instructions/control_flow.ts index 33e38c7d4fd..c38dec3ab8f 100644 --- a/packages/core/src/render3/instructions/control_flow.ts +++ b/packages/core/src/render3/instructions/control_flow.ts @@ -440,13 +440,13 @@ class LiveCollectionLContainerImpl extends LiveCollection< new RepeaterContext(this.lContainer, value, index), {dehydratedView}, ); - this.operationsCounter?.recordCreate(); + ngDevMode && this.operationsCounter?.recordCreate(); return embeddedLView; } override destroy(lView: LView>): void { destroyLView(lView[TVIEW], lView); - this.operationsCounter?.recordDestroy(); + ngDevMode && this.operationsCounter?.recordDestroy(); } override updateValue(index: number, value: unknown): void { this.getLView(index)[CONTEXT].$implicit = value; @@ -454,7 +454,7 @@ class LiveCollectionLContainerImpl extends LiveCollection< reset(): void { this.needsIndexUpdate = false; - this.operationsCounter?.reset(); + ngDevMode && this.operationsCounter?.reset(); } updateIndexes(): void {