Skip to content

Commit

Permalink
refactor(core): use performance API for control flow and standalone (a…
Browse files Browse the repository at this point in the history
…ngular#52370)

This commit adds a standard performance marker that can be viewed in Chrome dev tools and other tooling.
See more info at https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark

PR Close angular#52370
  • Loading branch information
pkozlowski-opensource authored and alxhub committed Oct 31, 2023
1 parent ac2d0c6 commit 225914b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/render3/features/standalone_feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class StandaloneService implements OnDestroy {
});
}

const PERF_MARK_STANDALONE = {
detail: {feature: 'NgStandalone'}
};

/**
* A feature that acts as a setup code for the {@link StandaloneService}.
*
Expand All @@ -71,6 +75,7 @@ class StandaloneService implements OnDestroy {
* @codeGenApi
*/
export function ɵɵStandaloneFeature(definition: ComponentDef<unknown>) {
performance.mark('mark_use_counter', PERF_MARK_STANDALONE);
definition.getStandaloneInjector = (parentInjector: EnvironmentInjector) => {
return parentInjector.get(StandaloneService).getOrCreateStandaloneInjector(definition);
};
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/render3/instructions/control_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {addLViewToLContainer, createAndRenderEmbeddedLView, getLViewFromLContain

import {ɵɵtemplate} from './template';

const PERF_MARK_CONTROL_FLOW = {
detail: {feature: 'NgControlFlow'}
};

/**
* The conditional instruction represents the basic building block on the runtime side to support
* built-in "if" and "switch". On the high level this instruction is responsible for adding and
Expand All @@ -36,6 +40,8 @@ import {ɵɵtemplate} from './template';
* @codeGenApi
*/
export function ɵɵconditional<T>(containerIndex: number, matchingTemplateIndex: number, value?: T) {
performance.mark('mark_use_counter', PERF_MARK_CONTROL_FLOW);

const hostLView = getLView();
const bindingIndex = nextBindingIndex();
const lContainer = getLContainer(hostLView, HEADER_OFFSET + containerIndex);
Expand Down Expand Up @@ -132,6 +138,8 @@ export function ɵɵrepeaterCreate(
index: number, templateFn: ComponentTemplate<unknown>, decls: number, vars: number,
trackByFn: TrackByFunction<unknown>, trackByUsesComponentInstance?: boolean,
emptyTemplateFn?: ComponentTemplate<unknown>, emptyDecls?: number, emptyVars?: number): void {
performance.mark('mark_use_counter', PERF_MARK_CONTROL_FLOW);

const hasEmptyBlock = emptyTemplateFn !== undefined;
const hostLView = getLView();
const boundTrackBy = trackByUsesComponentInstance ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@
{
"name": "PARAM_REGEX"
},
{
"name": "PERF_MARK_STANDALONE"
},
{
"name": "PLATFORM_DESTROY_LISTENERS"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@
{
"name": "Observable"
},
{
"name": "PERF_MARK_STANDALONE"
},
{
"name": "PLATFORM_DESTROY_LISTENERS"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@
{
"name": "Observable"
},
{
"name": "PERF_MARK_STANDALONE"
},
{
"name": "PLATFORM_DESTROY_LISTENERS"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@
{
"name": "OutletInjector"
},
{
"name": "PERF_MARK_STANDALONE"
},
{
"name": "PLATFORM_DESTROY_LISTENERS"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@
{
"name": "Observable"
},
{
"name": "PERF_MARK_STANDALONE"
},
{
"name": "PLATFORM_DESTROY_LISTENERS"
},
Expand Down

0 comments on commit 225914b

Please sign in to comment.