Skip to content

Commit 2934bd9

Browse files
committed
refactor(core): drop unused ngDevMode metrics
This commit updates the code to drop unused `ngDevMode` metrics and removes some related (and now unused) utility functions.
1 parent 916f768 commit 2934bd9

File tree

11 files changed

+1
-113
lines changed

11 files changed

+1
-113
lines changed

packages/core/src/render3/instructions/element_container.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ function elementContainerStartFirstCreatePass(
5858
attrsIndex?: number | null,
5959
localRefsIndex?: number,
6060
): TElementContainerNode {
61-
ngDevMode && ngDevMode.firstCreatePass++;
62-
6361
const tViewConsts = tView.consts;
6462
const attrs = getConstant<TAttributes>(tViewConsts, attrsIndex);
6563
const tNode = getOrCreateTNode(tView, index, TNodeType.ElementContainer, 'ng-container', attrs);

packages/core/src/render3/instructions/template.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ function templateFirstCreatePass(
6767
localRefsIndex?: number | null,
6868
): TContainerNode {
6969
ngDevMode && assertFirstCreatePass(tView);
70-
ngDevMode && ngDevMode.firstCreatePass++;
7170
const tViewConsts = tView.consts;
7271

7372
// TODO(pk): refactor getOrCreateTNode to have the "create" only version

packages/core/src/render3/tnode_manipulation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ export function createTNode(
266266
// `view_engine_compatibility` for additional context.
267267
assertGreaterThanOrEqual(index, HEADER_OFFSET, "TNodes can't be in the LView header.");
268268
ngDevMode && assertNotSame(attrs, undefined, "'undefined' is not valid value for 'attrs'");
269-
ngDevMode && ngDevMode.tNode++;
270269
ngDevMode && tParent && assertTNodeForTView(tParent, tView);
271270
let injectorIndex = tParent ? tParent.injectorIndex : -1;
272271
let flags = 0;

packages/core/src/render3/view/construction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export function createTView(
7777
constsOrFactory: TConstantsOrFactory | null,
7878
ssrId: string | null,
7979
): TView {
80-
ngDevMode && ngDevMode.tView++;
8180
const bindingStartIndex = HEADER_OFFSET + decls;
8281
// This length does not yet contain host bindings from child directives because at this point,
8382
// we don't know which directives are active on this template. As soon as a directive is matched

packages/core/src/render3/view/elements.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export function elementStartFirstCreatePass(
2828
localRefsIndex?: number,
2929
): TElementNode {
3030
ngDevMode && assertFirstCreatePass(tView);
31-
ngDevMode && ngDevMode.firstCreatePass++;
3231

3332
const tViewConsts = tView.consts;
3433
const attrs = getConstant<TAttributes>(tViewConsts, attrsIndex);

packages/core/src/util/ng_dev_mode.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ declare global {
2626
const ngDevMode: null | NgDevModePerfCounters;
2727

2828
interface NgDevModePerfCounters {
29-
namedConstructors: boolean;
30-
firstCreatePass: number;
31-
tNode: number;
32-
tView: number;
3329
hydratedNodes: number;
3430
hydratedComponents: number;
3531
dehydratedViewsRemoved: number;
@@ -39,13 +35,9 @@ declare global {
3935
}
4036
}
4137

42-
export function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
38+
function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
4339
const locationString = typeof location !== 'undefined' ? location.toString() : '';
4440
const newCounters: NgDevModePerfCounters = {
45-
namedConstructors: locationString.indexOf('ngDevMode=namedConstructors') != -1,
46-
firstCreatePass: 0,
47-
tNode: 0,
48-
tView: 0,
4941
hydratedNodes: 0,
5042
hydratedComponents: 0,
5143
dehydratedViewsRemoved: 0,
@@ -84,9 +76,6 @@ export function ngDevModeResetPerfCounters(): NgDevModePerfCounters {
8476
* get a `ReferenceError` like in https://github.com/angular/angular/issues/31595.
8577
*
8678
* Details on possible values for `ngDevMode` can be found on its docstring.
87-
*
88-
* NOTE:
89-
* - changes to the `ngDevMode` name must be synced with `compiler-cli/src/tooling.ts`.
9079
*/
9180
export function initNgDevMode(): boolean {
9281
// The below checks are to ensure that calling `initNgDevMode` multiple times does not

packages/core/test/acceptance/integration_spec.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ import {getLViewById} from '../../src/render3/interfaces/lview_tracking';
3535
import {isLView} from '../../src/render3/interfaces/type_checks';
3636
import {ID, LView, PARENT, TVIEW} from '../../src/render3/interfaces/view';
3737
import {getLView} from '../../src/render3/state';
38-
import {ngDevModeResetPerfCounters} from '../../src/util/ng_dev_mode';
3938
import {fakeAsync, flushMicrotasks, TestBed} from '../../testing';
4039
import {By} from '@angular/platform-browser';
4140
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
42-
import {expectPerfCounters} from '@angular/private/testing';
4341

4442
describe('acceptance integration tests', () => {
4543
function stripHtmlComments(str: string) {
@@ -59,44 +57,6 @@ describe('acceptance integration tests', () => {
5957

6058
expect(fixture.nativeElement.innerHTML).toEqual('<span title="Hello">Greetings</span>');
6159
});
62-
63-
it('should render and update basic "Hello, World" template', () => {
64-
ngDevModeResetPerfCounters();
65-
@Component({
66-
template: '<h1>Hello, {{name}}!</h1>',
67-
standalone: false,
68-
})
69-
class App {
70-
name = '';
71-
}
72-
73-
expectPerfCounters({
74-
tView: 0,
75-
tNode: 0,
76-
});
77-
78-
TestBed.configureTestingModule({declarations: [App]});
79-
const fixture = TestBed.createComponent(App);
80-
81-
fixture.componentInstance.name = 'World';
82-
fixture.detectChanges();
83-
84-
expect(fixture.nativeElement.innerHTML).toEqual('<h1>Hello, World!</h1>');
85-
expectPerfCounters({
86-
tView: 2, // Host view + App
87-
tNode: 3, // Host Node + <h1> + #text
88-
});
89-
90-
fixture.componentInstance.name = 'New World';
91-
fixture.detectChanges();
92-
93-
expect(fixture.nativeElement.innerHTML).toEqual('<h1>Hello, New World!</h1>');
94-
// Assert that the tView/tNode count does not increase (they are correctly cached)
95-
expectPerfCounters({
96-
tView: 2,
97-
tNode: 3,
98-
});
99-
});
10060
});
10161

10262
describe('ng-container', () => {

packages/core/test/acceptance/renderer_factory_spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
ViewEncapsulation,
2727
} from '../../src/core';
2828
import {RElement} from '../../src/render3/interfaces/renderer_dom';
29-
import {ngDevModeResetPerfCounters} from '../../src/util/ng_dev_mode';
3029
import {NoopNgZone} from '../../src/zone/ng_zone';
3130
import {TestBed} from '../../testing';
3231
import {EventManager, ɵSharedStylesHost} from '@angular/platform-browser';
@@ -477,10 +476,6 @@ describe('Renderer2 destruction hooks', () => {
477476
}
478477

479478
beforeEach(() => {
480-
// Tests below depend on perf counters when running with Ivy. In order to have
481-
// clean perf counters at the beginning of a test, we reset those here.
482-
ngDevModeResetPerfCounters();
483-
484479
TestBed.configureTestingModule({
485480
declarations: [SimpleApp, AppWithComponents, BasicComponent],
486481
providers: [

packages/core/test/acceptance/styling_spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ViewContainerRef,
1919
} from '../../src/core';
2020
import {bypassSanitizationTrustStyle} from '../../src/sanitization/bypass';
21-
import {ngDevModeResetPerfCounters} from '../../src/util/ng_dev_mode';
2221
import {TestBed} from '../../testing';
2322
import {
2423
getElementClasses,
@@ -27,11 +26,8 @@ import {
2726
getSortedStyle,
2827
} from '../../testing/src/styling';
2928
import {By, DomSanitizer, SafeStyle} from '@angular/platform-browser';
30-
import {expectPerfCounters} from '@angular/private/testing';
3129

3230
describe('styling', () => {
33-
beforeEach(ngDevModeResetPerfCounters);
34-
3531
describe('apply in prioritization order', () => {
3632
it('should perform static bindings', () => {
3733
@Component({
@@ -1917,9 +1913,6 @@ describe('styling', () => {
19171913
expect(element.style.height).toEqual('900px');
19181914
expect(element.style.fontSize).toEqual('100px');
19191915

1920-
// once for the template flush and again for the host bindings
1921-
ngDevModeResetPerfCounters();
1922-
19231916
component.opacity = '0.6';
19241917
component.compWithStyling!.height = '100px';
19251918
component.compWithStyling!.width = '100px';
@@ -2217,75 +2210,65 @@ describe('styling', () => {
22172210
const fixture = TestBed.createComponent(Cmp);
22182211
const comp = fixture.componentInstance;
22192212

2220-
ngDevModeResetPerfCounters();
22212213
fixture.detectChanges();
22222214
const element = fixture.nativeElement.querySelector('div');
22232215

22242216
assertStyle(element, 'width', '111px');
22252217
assertStyle(element, 'height', '111px');
22262218

22272219
comp.width = '222px';
2228-
ngDevModeResetPerfCounters();
22292220
fixture.detectChanges();
22302221

22312222
assertStyle(element, 'width', '222px');
22322223
assertStyle(element, 'height', '111px');
22332224

22342225
comp.height = '222px';
2235-
ngDevModeResetPerfCounters();
22362226
fixture.detectChanges();
22372227

22382228
assertStyle(element, 'width', '222px');
22392229
assertStyle(element, 'height', '222px');
22402230

22412231
comp.width = undefined;
2242-
ngDevModeResetPerfCounters();
22432232
fixture.detectChanges();
22442233

22452234
assertStyle(element, 'width', '555px');
22462235
assertStyle(element, 'height', '222px');
22472236

22482237
comp.width = '123px';
22492238
comp.height = '123px';
2250-
ngDevModeResetPerfCounters();
22512239
fixture.detectChanges();
22522240

22532241
assertStyle(element, 'width', '123px');
22542242
assertStyle(element, 'height', '123px');
22552243

22562244
comp.map = {};
2257-
ngDevModeResetPerfCounters();
22582245
fixture.detectChanges();
22592246

22602247
// No change, hence no write
22612248
assertStyle(element, 'width', '123px');
22622249
assertStyle(element, 'height', '123px');
22632250

22642251
comp.width = undefined;
2265-
ngDevModeResetPerfCounters();
22662252
fixture.detectChanges();
22672253

22682254
assertStyle(element, 'width', '999px');
22692255
assertStyle(element, 'height', '123px');
22702256

22712257
comp.dir.map = null;
2272-
ngDevModeResetPerfCounters();
22732258
fixture.detectChanges();
22742259

22752260
// the width is only applied once
22762261
assertStyle(element, 'width', '0px');
22772262
assertStyle(element, 'height', '123px');
22782263

22792264
comp.dir.map = {width: '1000px', height: '1100px', color: 'red'};
2280-
ngDevModeResetPerfCounters();
22812265
fixture.detectChanges();
22822266

22832267
assertStyle(element, 'width', '1000px');
22842268
assertStyle(element, 'height', '123px');
22852269
assertStyle(element, 'color', 'red');
22862270

22872271
comp.height = undefined;
2288-
ngDevModeResetPerfCounters();
22892272
fixture.detectChanges();
22902273

22912274
// height gets applied twice and all other
@@ -2295,7 +2278,6 @@ describe('styling', () => {
22952278
assertStyle(element, 'color', 'red');
22962279

22972280
comp.map = {color: 'blue', width: '2000px', opacity: '0.5'};
2298-
ngDevModeResetPerfCounters();
22992281
fixture.detectChanges();
23002282

23012283
assertStyle(element, 'width', '2000px');
@@ -2304,7 +2286,6 @@ describe('styling', () => {
23042286
assertStyle(element, 'opacity', '0.5');
23052287

23062288
comp.map = {color: 'blue', width: '2000px'};
2307-
ngDevModeResetPerfCounters();
23082289
fixture.detectChanges();
23092290

23102291
// all four are applied because the map was altered

packages/core/test/acceptance/view_container_ref_spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
ViewContainerRef,
4444
ɵsetDocument,
4545
} from '../../src/core';
46-
import {ngDevModeResetPerfCounters} from '../../src/util/ng_dev_mode';
4746
import {ComponentFixture, TestBed, TestComponentRenderer} from '../../testing';
4847
import {clearTranslations, loadTranslations} from '@angular/localize';
4948
import {By, DomSanitizer} from '@angular/platform-browser';
@@ -880,10 +879,6 @@ describe('ViewContainerRef', () => {
880879
describe('detach', () => {
881880
beforeEach(() => {
882881
TestBed.configureTestingModule({declarations: [EmbeddedViewInsertionComp, VCRefDirective]});
883-
884-
// Tests depend on perf counters. In order to have clean perf counters at the beginning of a
885-
// test, we reset those here.
886-
ngDevModeResetPerfCounters();
887882
});
888883

889884
it('should detach the right embedded view when an index is specified', () => {
@@ -978,10 +973,6 @@ describe('ViewContainerRef', () => {
978973
renderer.destroyNode = () => {};
979974
return renderer;
980975
};
981-
982-
// Tests depend on perf counters. In order to have clean perf counters at the beginning of a
983-
// test, we reset those here.
984-
ngDevModeResetPerfCounters();
985976
});
986977

987978
it('should remove the right embedded view when an index is specified', () => {

0 commit comments

Comments
 (0)