Skip to content

Commit 265154f

Browse files
committed
feat(profile): place performance measures behind --profile flag
1 parent b444b45 commit 265154f

15 files changed

Lines changed: 55 additions & 47 deletions

src/cli/parse-flags.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ const ARG_OPTS = {
169169
'log',
170170
'open',
171171
'prerender',
172-
'service-worker',
173172
'prod',
173+
'profile',
174+
'service-worker',
174175
'screenshot',
175176
'serve',
176177
'skip-node-check',

src/cli/test/parse-flags.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ describe('parseFlags', () => {
348348
expect(flags.prod).toBe(true);
349349
});
350350

351+
it('should parse --profile', () => {
352+
process.argv[2] = '--profile';
353+
const flags = parseFlags(process);
354+
expect(flags.profile).toBe(true);
355+
});
356+
351357
it('should parse --prerender', () => {
352358
process.argv[2] = '--prerender';
353359
const flags = parseFlags(process);

src/client/platform-main-legacy.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { queueUpdate } from '../core/update';
1818

1919
export function createPlatformMainLegacy(namespace: string, Context: d.CoreContext, win: d.WindowData, doc: Document, resourcesUrl: string, hydratedCssClass: string, components: d.ComponentHostData[], customStyle: CustomStyle) {
2020
const perf = win.performance;
21-
if (__BUILD_CONDITIONALS__.perf) {
21+
if (__BUILD_CONDITIONALS__.profile) {
2222
perf.mark(`app_load_start`);
2323
}
2424

@@ -117,7 +117,7 @@ export function createPlatformMainLegacy(namespace: string, Context: d.CoreConte
117117
plt.isCmpReady.set(rootElm, App.loaded = plt.isAppLoaded = true);
118118
domApi.$dispatchEvent(win, 'appload', { detail: { namespace: namespace } });
119119

120-
if (__BUILD_CONDITIONALS__.perf) {
120+
if (__BUILD_CONDITIONALS__.profile) {
121121
perf.mark('app_load_end');
122122
perf.measure('app_load', 'app_load_start', 'app_load_end');
123123
}
@@ -164,14 +164,14 @@ export function createPlatformMainLegacy(namespace: string, Context: d.CoreConte
164164
HostElementConstructor.observedAttributes = observedAttributes;
165165
}
166166

167-
if (__BUILD_CONDITIONALS__.perf) {
167+
if (__BUILD_CONDITIONALS__.profile) {
168168
perf.mark(`define_start:${cmpMeta.tagNameMeta}`);
169169
}
170170

171171
// define the custom element
172172
win.customElements.define(cmpMeta.tagNameMeta, HostElementConstructor);
173173

174-
if (__BUILD_CONDITIONALS__.perf) {
174+
if (__BUILD_CONDITIONALS__.profile) {
175175
perf.mark(`define_end:${cmpMeta.tagNameMeta}`);
176176
perf.measure(`define:${cmpMeta.tagNameMeta}`, `define_start:${cmpMeta.tagNameMeta}`, `define_end:${cmpMeta.tagNameMeta}`);
177177
}
@@ -391,7 +391,7 @@ export function createPlatformMainLegacy(namespace: string, Context: d.CoreConte
391391
}
392392

393393
// register all the components now that everything's ready
394-
if (__BUILD_CONDITIONALS__.perf) {
394+
if (__BUILD_CONDITIONALS__.profile) {
395395
perf.mark(`define_custom_elements_start`);
396396
}
397397

@@ -415,7 +415,7 @@ export function createPlatformMainLegacy(namespace: string, Context: d.CoreConte
415415
}
416416
);
417417

418-
if (__BUILD_CONDITIONALS__.perf) {
418+
if (__BUILD_CONDITIONALS__.profile) {
419419
perf.mark(`define_custom_elements_end`);
420420
perf.measure(`define_custom_elements`, `define_custom_elements_start`, `define_custom_elements_end`);
421421
}

src/client/platform-main.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { queueUpdate } from '../core/update';
1818

1919
export function createPlatformMain(namespace: string, Context: d.CoreContext, win: d.WindowData, doc: Document, resourcesUrl: string, hydratedCssClass: string, components: d.ComponentHostData[]) {
2020
const perf = win.performance;
21-
if (__BUILD_CONDITIONALS__.perf) {
21+
if (__BUILD_CONDITIONALS__.profile) {
2222
perf.mark(`app_load_start`);
2323
}
2424

@@ -110,7 +110,7 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
110110
plt.isCmpReady.set(rootElm, App.loaded = plt.isAppLoaded = true);
111111
domApi.$dispatchEvent(win, 'appload', { detail: { namespace: namespace } });
112112

113-
if (__BUILD_CONDITIONALS__.perf) {
113+
if (__BUILD_CONDITIONALS__.profile) {
114114
perf.mark('app_load_end');
115115
perf.measure('app_load', 'app_load_start', 'app_load_end');
116116
}
@@ -151,13 +151,13 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
151151
.filter(attribName => !!attribName);
152152
}
153153

154-
if (__BUILD_CONDITIONALS__.perf) {
154+
if (__BUILD_CONDITIONALS__.profile) {
155155
perf.mark(`define_start:${cmpMeta.tagNameMeta}`);
156156
}
157157

158158
win.customElements.define(cmpMeta.tagNameMeta, HostElementConstructor);
159159

160-
if (__BUILD_CONDITIONALS__.perf) {
160+
if (__BUILD_CONDITIONALS__.profile) {
161161
perf.mark(`define_end:${cmpMeta.tagNameMeta}`);
162162
perf.measure(`define:${cmpMeta.tagNameMeta}`, `define_start:${cmpMeta.tagNameMeta}`, `define_end:${cmpMeta.tagNameMeta}`);
163163
}
@@ -166,15 +166,15 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
166166

167167

168168
function requestBundle(cmpMeta: d.ComponentMeta, elm: d.HostElement, hmrVersionId: string) {
169-
if (__BUILD_CONDITIONALS__.perf) {
169+
if (__BUILD_CONDITIONALS__.profile) {
170170
perf.mark(`request_bundle_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
171171
}
172172

173173
if (cmpMeta.componentConstructor) {
174174
// we're already all loaded up :)
175175
queueUpdate(plt, elm, perf);
176176

177-
if (__BUILD_CONDITIONALS__.perf) {
177+
if (__BUILD_CONDITIONALS__.profile) {
178178
perf.mark(`request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
179179
perf.measure(`request_bundle:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
180180
}
@@ -192,7 +192,7 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
192192
(cmpMeta.bundleIds as d.GetModuleFn)(moduleOpts).then(cmpConstructor => {
193193
// async loading of the module is done
194194

195-
if (__BUILD_CONDITIONALS__.perf) {
195+
if (__BUILD_CONDITIONALS__.profile) {
196196
perf.mark(`request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
197197
perf.measure(`request_bundle:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
198198
}
@@ -246,7 +246,7 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
246246
__import(url).then(importedModule => {
247247
// async loading of the module is done
248248

249-
if (__BUILD_CONDITIONALS__.perf) {
249+
if (__BUILD_CONDITIONALS__.profile) {
250250
perf.mark(`request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
251251
perf.measure(`request_bundle:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `request_bundle_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
252252
}
@@ -287,15 +287,15 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
287287
if (__BUILD_CONDITIONALS__.browserModuleLoader) {
288288
// register all the components now that everything's ready
289289
// standard es2017 class extends HTMLElement
290-
if (__BUILD_CONDITIONALS__.perf) {
290+
if (__BUILD_CONDITIONALS__.profile) {
291291
perf.mark(`define_custom_elements_start`);
292292
}
293293

294294
components
295295
.map(parseComponentLoader)
296296
.forEach(cmpMeta => defineComponent(cmpMeta, class extends HTMLElement {}));
297297

298-
if (__BUILD_CONDITIONALS__.perf) {
298+
if (__BUILD_CONDITIONALS__.profile) {
299299
perf.mark(`define_custom_elements_end`);
300300
perf.measure(`define_custom_elements`, `define_custom_elements_start`, `define_custom_elements_end`);
301301
}

src/core/connected.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function connectedCallback(plt: d.PlatformApi, cmpMeta: d.ComponentMeta,
2828
elm['s-id'] = plt.nextId();
2929
}
3030

31-
if (__BUILD_CONDITIONALS__.perf) {
31+
if (__BUILD_CONDITIONALS__.profile) {
3232
perf.mark(`connected_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
3333
}
3434

@@ -52,7 +52,7 @@ export function connectedCallback(plt: d.PlatformApi, cmpMeta: d.ComponentMeta,
5252
// if it's already loaded then the callback will be synchronous
5353
plt.hostSnapshotMap.set(elm, initHostSnapshot(plt.domApi, cmpMeta, elm));
5454

55-
if (__BUILD_CONDITIONALS__.perf) {
55+
if (__BUILD_CONDITIONALS__.profile) {
5656
perf.mark(`connected_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
5757
perf.measure(`connected:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `connected_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `connected_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
5858
}

src/core/disconnected.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function disconnectedCallback(plt: PlatformApi, elm: HostElement, perf: P
88
// only disconnect if we're not temporarily disconnected
99
// tmpDisconnected will happen when slot nodes are being relocated
1010
if (!plt.tmpDisconnected && isDisconnected(plt.domApi, elm)) {
11-
if (__BUILD_CONDITIONALS__.perf) {
11+
if (__BUILD_CONDITIONALS__.profile) {
1212
perf.mark(`disconnected_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
1313
}
1414

@@ -55,7 +55,7 @@ export function disconnectedCallback(plt: PlatformApi, elm: HostElement, perf: P
5555
plt.hostSnapshotMap
5656
].forEach(wm => wm.delete(elm));
5757

58-
if (__BUILD_CONDITIONALS__.perf) {
58+
if (__BUILD_CONDITIONALS__.profile) {
5959
perf.mark(`disconnected_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
6060
perf.measure(`disconnected:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `disconnected_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `disconnected_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
6161
}

src/core/init-component-instance.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function initComponentInstance(
1717
) {
1818
try {
1919

20-
if (__BUILD_CONDITIONALS__.perf) {
20+
if (__BUILD_CONDITIONALS__.profile) {
2121
perf.mark(`init_instance_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
2222
}
2323

@@ -73,7 +73,7 @@ export function initComponentInstance(
7373

7474
plt.instanceMap.set(elm, instance);
7575

76-
if (__BUILD_CONDITIONALS__.perf) {
76+
if (__BUILD_CONDITIONALS__.profile) {
7777
perf.mark(`init_instance_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
7878
perf.measure(`init_instance:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `init_instance_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `init_instance_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
7979
}
@@ -106,7 +106,7 @@ export function initComponentLoaded(plt: d.PlatformApi, elm: d.HostElement, hydr
106106
plt.isCmpReady.set(elm, true);
107107

108108
if (!(hasCmpLoaded = plt.isCmpLoaded.has(elm))) {
109-
if (__BUILD_CONDITIONALS__.perf) {
109+
if (__BUILD_CONDITIONALS__.profile) {
110110
perf.mark(`init_loaded_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
111111
}
112112

@@ -139,13 +139,13 @@ export function initComponentLoaded(plt: d.PlatformApi, elm: d.HostElement, hydr
139139
// componentDidLoad only runs ONCE, after the instance's element has been
140140
// assigned as the host element, and AFTER render() has been called
141141
// and all the child componenets have finished loading
142-
if (__BUILD_CONDITIONALS__.perf) {
142+
if (__BUILD_CONDITIONALS__.profile) {
143143
perf.mark(`componentDidLoad_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
144144
}
145145

146146
instance.componentDidLoad();
147147

148-
if (__BUILD_CONDITIONALS__.perf) {
148+
if (__BUILD_CONDITIONALS__.profile) {
149149
perf.mark(`componentDidLoad_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
150150
perf.measure(`componentDidLoad:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `componentDidLoad_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `componentDidLoad_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
151151
}
@@ -155,13 +155,13 @@ export function initComponentLoaded(plt: d.PlatformApi, elm: d.HostElement, hydr
155155
// fire off the user's componentDidUpdate method (if one was provided)
156156
// componentDidUpdate runs AFTER render() has been called
157157
// and all child components have finished updating
158-
if (__BUILD_CONDITIONALS__.perf) {
158+
if (__BUILD_CONDITIONALS__.profile) {
159159
perf.mark(`componentDidUpdate_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
160160
}
161161

162162
instance.componentDidUpdate();
163163

164-
if (__BUILD_CONDITIONALS__.perf) {
164+
if (__BUILD_CONDITIONALS__.profile) {
165165
perf.mark(`componentDidUpdate_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
166166
perf.measure(`componentDidUpdate:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `componentDidUpdate_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `componentDidUpdate_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
167167
}
@@ -171,7 +171,7 @@ export function initComponentLoaded(plt: d.PlatformApi, elm: d.HostElement, hydr
171171
plt.onError(e, RUNTIME_ERROR.DidLoadError, elm);
172172
}
173173

174-
if (__BUILD_CONDITIONALS__.perf && !hasCmpLoaded) {
174+
if (__BUILD_CONDITIONALS__.profile && !hasCmpLoaded) {
175175
perf.mark(`init_loaded_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
176176
perf.measure(`init_loaded:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `init_loaded_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `init_loaded_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
177177
perf.measure(`loaded:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `connected_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `init_loaded_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);

src/core/proxy-component-instance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function proxyComponentInstance(
1010
hostSnapshot: d.HostSnapshot,
1111
perf: Performance
1212
) {
13-
if (__BUILD_CONDITIONALS__.perf) {
13+
if (__BUILD_CONDITIONALS__.profile) {
1414
perf.mark(`proxy_instance_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
1515
}
1616

@@ -39,7 +39,7 @@ export function proxyComponentInstance(
3939
defineMember(plt, property, elm, instance, memberName, hostSnapshot, perf);
4040
});
4141

42-
if (__BUILD_CONDITIONALS__.perf) {
42+
if (__BUILD_CONDITIONALS__.profile) {
4343
perf.mark(`proxy_instance_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
4444
perf.measure(`proxy_instance:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `proxy_instance_start:${elm.nodeName.toLowerCase()}:${elm['s-id']}`, `proxy_instance_end:${elm.nodeName.toLowerCase()}:${elm['s-id']}`);
4545
}

src/core/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { RUNTIME_ERROR } from '../util/constants';
77

88
export function render(plt: d.PlatformApi, cmpMeta: d.ComponentMeta, hostElm: d.HostElement, instance: d.ComponentInstance, perf: Performance) {
99
try {
10-
if (__BUILD_CONDITIONALS__.perf) {
10+
if (__BUILD_CONDITIONALS__.profile) {
1111
perf.mark(`render_start:${hostElm.nodeName.toLowerCase()}`);
1212
}
1313

@@ -149,7 +149,7 @@ export function render(plt: d.PlatformApi, cmpMeta: d.ComponentMeta, hostElm: d.
149149
hostElm['s-rc'] = null;
150150
}
151151

152-
if (__BUILD_CONDITIONALS__.perf) {
152+
if (__BUILD_CONDITIONALS__.profile) {
153153
perf.mark(`render_end:${hostElm.nodeName.toLowerCase()}`);
154154
perf.measure(`render:${hostElm.nodeName.toLowerCase()}`, `render_start:${hostElm.nodeName.toLowerCase()}`, `render_end:${hostElm.nodeName.toLowerCase()}`);
155155
}

src/core/styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getScopeId } from '../util/scope';
66
export function initStyleTemplate(domApi: d.DomApi, cmpMeta: d.ComponentMeta, encapsulation: ENCAPSULATION, style: string, styleMode: string, perf: Performance) {
77
if (style) {
88

9-
if (__BUILD_CONDITIONALS__.perf) {
9+
if (__BUILD_CONDITIONALS__.profile) {
1010
perf.mark(`init_style_template_start:${cmpMeta.tagNameMeta}`);
1111
}
1212

@@ -67,7 +67,7 @@ export function initStyleTemplate(domApi: d.DomApi, cmpMeta: d.ComponentMeta, en
6767
}
6868
}
6969

70-
if (__BUILD_CONDITIONALS__.perf) {
70+
if (__BUILD_CONDITIONALS__.profile) {
7171
perf.mark(`init_style_template_end:${cmpMeta.tagNameMeta}`);
7272
perf.measure(`init_style_template:${cmpMeta.tagNameMeta}`, `init_style_template_start:${cmpMeta.tagNameMeta}`, `init_style_template_end:${cmpMeta.tagNameMeta}`);
7373
}

0 commit comments

Comments
 (0)