Skip to content

Commit 4c13fe9

Browse files
committed
Add profiling for some key points in the nativescript-angular lifecycle
1 parent 4521c7c commit 4c13fe9

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

Diff for: nativescript-angular/directives/list-view-comp.ts

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ListView, ItemEventData } from "tns-core-modules/ui/list-view";
2323
import { View, KeyedTemplate } from "tns-core-modules/ui/core/view";
2424
import { ObservableArray } from "tns-core-modules/data/observable-array";
2525
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
26+
import { profile } from "tns-core-modules/profiling";
2627

2728
import { CommentNode } from "../element-registry";
2829
import { isListLikeIterable } from "../collection-facade";
@@ -148,6 +149,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit {
148149
this._templateMap.set(key, keyedTemplate);
149150
}
150151

152+
@profile
151153
public onItemLoading(args: ItemEventData) {
152154
if (!args.view && !this.itemTemplate) {
153155
return;
@@ -195,6 +197,7 @@ export class ListViewComponent implements DoCheck, OnDestroy, AfterContentInit {
195197
this.setupItemView.next({ view: viewRef, data: data, index: index, context: context });
196198
}
197199

200+
@profile
198201
private detectChangesOnChild(viewRef: EmbeddedViewRef<ListItemContext>, index: number) {
199202
listViewLog("Manually detect changes in child: " + index);
200203
viewRef.markForCheck();

Diff for: nativescript-angular/platform-common.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "./zone-js/dist/zone-nativescript";
66
import "reflect-metadata";
77
import "./polyfills/array";
88
import "./polyfills/console";
9+
import { profile } from "tns-core-modules/profiling";
910

1011
import {
1112
Type,
@@ -68,6 +69,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
6869
super();
6970
}
7071

72+
@profile
7173
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
7274
this._bootstrapper = () => this.platform.bootstrapModuleFactory(moduleFactory);
7375

@@ -76,6 +78,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
7678
return null; // Make the compiler happy
7779
}
7880

81+
@profile
7982
bootstrapModule<M>(
8083
moduleType: Type<M>,
8184
compilerOptions: CompilerOptions | CompilerOptions[] = []
@@ -87,6 +90,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
8790
return null; // Make the compiler happy
8891
}
8992

93+
@profile
9094
private bootstrapApp() {
9195
(<any>global).__onLiveSyncCore = () => this.livesyncModule();
9296

@@ -139,6 +143,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
139143
return this.platform.destroyed;
140144
}
141145

146+
@profile
142147
private createNavigationEntry(
143148
bootstrapAction: BootstrapperAction,
144149
resolve?: (comp: NgModuleRef<any>) => void,
@@ -156,14 +161,14 @@ export class NativeScriptPlatformRef extends PlatformRef {
156161
page.actionBarHidden = this.appOptions.startPageActionBarHidden;
157162
}
158163

159-
let initHandler = function () {
164+
let initHandler = profile("nativescript-angular/platform-common.initHandler", function () {
160165
page.off(Page.navigatingToEvent, initHandler);
161166
// profiling.stop("application-start");
162167
rendererLog("Page loaded");
163168

164169
// profiling.start("ng-bootstrap");
165170
rendererLog("BOOTSTRAPPING...");
166-
bootstrapAction().then((moduleRef) => {
171+
bootstrapAction().then(profile("nativescript-angular/platform-common.postBootstrapAction", (moduleRef) => {
167172
// profiling.stop("ng-bootstrap");
168173
rendererLog("ANGULAR BOOTSTRAP DONE.");
169174
lastBootstrappedModule = new WeakRef(moduleRef);
@@ -172,7 +177,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
172177
resolve(moduleRef);
173178
}
174179
return moduleRef;
175-
}, (err) => {
180+
}), (err) => {
176181
rendererError("ERROR BOOTSTRAPPING ANGULAR");
177182
let errorMessage = err.message + "\n\n" + err.stack;
178183
rendererError(errorMessage);
@@ -185,7 +190,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
185190
reject(err);
186191
}
187192
});
188-
};
193+
});
189194

190195
page.on(Page.navigatingToEvent, initHandler);
191196

Diff for: nativescript-angular/renderer.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Device } from "tns-core-modules/platform";
88
import { View } from "tns-core-modules/ui/core/view";
99
import { addCss } from "tns-core-modules/application";
1010
import { topmost } from "tns-core-modules/ui/frame";
11+
import { profile } from "tns-core-modules/profiling";
1112

1213
import { APP_ROOT_VIEW, DEVICE, getRootPage } from "./platform-providers";
1314
import { isBlank } from "./lang-facade";
@@ -83,119 +84,143 @@ export class NativeScriptRenderer extends Renderer2 {
8384
traceLog("NativeScriptRenderer created");
8485
}
8586

87+
@profile
8688
appendChild(parent: any, newChild: NgView): void {
8789
traceLog(`NativeScriptRenderer.appendChild child: ${newChild} parent: ${parent}`);
8890
this.viewUtil.insertChild(parent, newChild);
8991
}
9092

93+
@profile
9194
insertBefore(parent: NgView, newChild: NgView, refChildIndex: number): void {
9295
traceLog(`NativeScriptRenderer.insertBefore child: ${newChild} parent: ${parent}`);
9396
this.viewUtil.insertChild(parent, newChild, refChildIndex);
9497
}
9598

99+
@profile
96100
removeChild(parent: any, oldChild: NgView): void {
97101
traceLog(`NativeScriptRenderer.removeChild child: ${oldChild} parent: ${parent}`);
98102
this.viewUtil.removeChild(parent, oldChild);
99103
}
100104

105+
@profile
101106
selectRootElement(selector: string): NgView {
102107
traceLog("selectRootElement: " + selector);
103108
return this.rootView;
104109
}
105110

111+
@profile
106112
parentNode(node: NgView): any {
107113
return node.parent || node.templateParent;
108114
}
109115

116+
@profile
110117
nextSibling(node: NgView): number {
111118
traceLog(`NativeScriptRenderer.nextSibling ${node}`);
112119
return this.viewUtil.nextSiblingIndex(node);
113120
}
114121

122+
@profile
115123
createComment(_value: any): CommentNode {
116124
traceLog(`NativeScriptRenderer.createComment ${_value}`);
117125
return this.viewUtil.createComment();
118126
}
119127

128+
@profile
120129
createElement(name: any, _namespace: string): NgView {
121130
traceLog(`NativeScriptRenderer.createElement: ${name}`);
122131
return this.viewUtil.createView(name);
123132
}
124133

134+
@profile
125135
createText(_value: string): CommentNode {
126136
traceLog(`NativeScriptRenderer.createText ${_value}`);
127137
return this.viewUtil.createText();
128138
}
129139

140+
@profile
130141
createViewRoot(hostElement: NgView): NgView {
131142
traceLog(`NativeScriptRenderer.createViewRoot ${hostElement.nodeName}`);
132143
return hostElement;
133144
}
134145

146+
@profile
135147
projectNodes(parentElement: NgView, nodes: NgView[]): void {
136148
traceLog("NativeScriptRenderer.projectNodes");
137149
nodes.forEach((node) => this.viewUtil.insertChild(parentElement, node));
138150
}
139151

152+
@profile
140153
destroy() {
141154
traceLog("NativeScriptRenderer.destroy");
142155
// Seems to be called on component dispose only (router outlet)
143156
// TODO: handle this when we resolve routing and navigation.
144157
}
145158

159+
@profile
146160
setAttribute(view: NgView, name: string, value: string, namespace?: string) {
147161
traceLog(`NativeScriptRenderer.setAttribute ${view} : ${name} = ${value}, namespace: ${namespace}`);
148162
return this.viewUtil.setProperty(view, name, value, namespace);
149163
}
150164

165+
@profile
151166
removeAttribute(_el: NgView, _name: string): void {
152167
traceLog(`NativeScriptRenderer.removeAttribute ${_el}: ${_name}`);
153168
}
154169

170+
@profile
155171
setProperty(view: any, name: string, value: any) {
156172
traceLog(`NativeScriptRenderer.setProperty ${view} : ${name} = ${value}`);
157173
return this.viewUtil.setProperty(view, name, value);
158174
}
159175

176+
@profile
160177
addClass(view: NgView, name: string): void {
161178
traceLog(`NativeScriptRenderer.addClass ${name}`);
162179
this.viewUtil.addClass(view, name);
163180
}
164181

182+
@profile
165183
removeClass(view: NgView, name: string): void {
166184
traceLog(`NativeScriptRenderer.removeClass ${name}`);
167185
this.viewUtil.removeClass(view, name);
168186
}
169187

188+
@profile
170189
setStyle(view: NgView, styleName: string, value: any, _flags?: RendererStyleFlags2): void {
171190
traceLog(`NativeScriptRenderer.setStyle: ${styleName} = ${value}`);
172191
this.viewUtil.setStyle(view, styleName, value);
173192
}
174193

194+
@profile
175195
removeStyle(view: NgView, styleName: string, _flags?: RendererStyleFlags2): void {
176196
traceLog("NativeScriptRenderer.removeStyle: ${styleName}");
177197
this.viewUtil.removeStyle(view, styleName);
178198
}
179199

180200
// Used only in debug mode to serialize property changes to comment nodes,
181201
// such as <template> placeholders.
202+
@profile
182203
setBindingDebugInfo(renderElement: NgView, propertyName: string, propertyValue: string): void {
183204
traceLog("NativeScriptRenderer.setBindingDebugInfo: " + renderElement + ", " +
184205
propertyName + " = " + propertyValue);
185206
}
186207

208+
@profile
187209
setElementDebugInfo(renderElement: any, _info: any /*RenderDebugInfo*/): void {
188210
traceLog("NativeScriptRenderer.setElementDebugInfo: " + renderElement);
189211
}
190212

213+
@profile
191214
invokeElementMethod(_renderElement: NgView, methodName: string, args: Array<any>) {
192215
traceLog("NativeScriptRenderer.invokeElementMethod " + methodName + " " + args);
193216
}
194217

218+
@profile
195219
setValue(_renderNode: any, _value: string) {
196220
traceLog("NativeScriptRenderer.setValue");
197221
}
198222

223+
@profile
199224
listen(renderElement: any, eventName: string, callback: (event: any) => boolean):
200225
() => void {
201226
traceLog("NativeScriptRenderer.listen: " + eventName);
@@ -251,16 +276,17 @@ class EmulatedRenderer extends NativeScriptRenderer {
251276
return view;
252277
}
253278

279+
@profile
254280
private addStyles(styles: (string | any[])[], componentId: string) {
255281
styles.map(s => s.toString())
256282
.map(s => replaceNgAttribute(s, componentId))
257283
.forEach(addStyleToCss);
258284
}
259285
}
260286

261-
function addStyleToCss(style: string): void {
287+
const addStyleToCss = profile('"renderer".addStyleToCss', function addStyleToCss(style: string): void {
262288
addCss(style);
263-
}
289+
});
264290

265291
function replaceNgAttribute(input: string, componentId: string): string {
266292
return input.replace(COMPONENT_REGEX, componentId);

Diff for: nativescript-angular/router/page-router-outlet.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ViewContainerRef, Type, InjectionToken,
44
Inject, ComponentFactoryResolver, Injector
55
} from "@angular/core";
6+
import { profile } from "tns-core-modules/profiling";
67
import { RouterOutletMap, ActivatedRoute, PRIMARY_OUTLET } from "@angular/router";
78
import { Device } from "tns-core-modules/platform";
89
import { Frame } from "tns-core-modules/ui/frame";
@@ -148,6 +149,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
148149
* Called by the Router to instantiate a new component during the commit phase of a navigation.
149150
* This method in turn is responsible for calling the `routerOnActivate` hook of its child.
150151
*/
152+
@profile
151153
activateWith(
152154
activatedRoute: ActivatedRoute, resolver: ComponentFactoryResolver|null,
153155
outletMap: RouterOutletMap): void {
@@ -231,6 +233,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
231233
this.currentActivatedComp = cacheItem.componentRef;
232234
}
233235

236+
@profile
234237
private loadComponentInPage(page: Page, componentRef: ComponentRef<any>): void {
235238
// Component loaded. Find its root native view.
236239
const componentView = componentRef.location.nativeElement;

0 commit comments

Comments
 (0)