Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit ef3fb7b

Browse files
mheverychirayuk
authored andcommitted
perf(WTF): extracted scopes to separate file, add documentation
Closes #1361
1 parent cc61dda commit ef3fb7b

19 files changed

+436
-166
lines changed

benchmark/web/wtf.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
library wtf_test_app;
22

3-
import 'package:angular/wtf.dart';
3+
import 'package:angular/tracing.dart';
44
import 'dart:html';
55
import 'dart:js' show context;
66

77
main() {
8-
traceInit(context);
8+
traceDetectWTF(context);
99
var _main = traceCreateScope('main()');
1010
var _querySelector = traceCreateScope('Node#querySelector()');
1111
var _DivElement = traceCreateScope('DivElement()');
@@ -21,7 +21,7 @@ main() {
2121
traceLeave(s);
2222

2323
s = traceEnter(_ElementText);
24-
div.text = 'Hello WTF! (enabled: ${wtfEnabled})';
24+
div.text = 'Hello WTF! (enabled: ${traceEnabled})';
2525
traceLeave(s);
2626

2727
s = traceEnter(_NodeAppend);

lib/angular.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export 'package:angular/application.dart';
55
export 'package:angular/core/module.dart';
66
export 'package:angular/directive/module.dart';
77
export 'package:angular/core/annotation.dart';
8+
export 'package:angular/tracing.dart';
89
export 'package:angular/introspection.dart' hide
910
elementExpando, publishToJavaScript;
1011
export 'package:angular/formatter/module.dart';

lib/application.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import 'package:angular/directive/module.dart';
8282
import 'package:angular/formatter/module_internal.dart';
8383
import 'package:angular/routing/module.dart';
8484
import 'package:angular/introspection.dart';
85-
import 'package:angular/wtf.dart';
85+
import 'package:angular/ng_tracing.dart';
8686

8787
import 'package:angular/core_dom/static_keys.dart';
8888
import 'package:angular/core_dom/directive_injector.dart';
@@ -130,7 +130,6 @@ class AngularModule extends Module {
130130
* applicationFactory to bootstrap your Angular application.
131131
*
132132
*/
133-
var _Application_run = traceCreateScope('Application#run()');
134133
abstract class Application {
135134
static _find(String selector, [dom.Element defaultElement]) {
136135
var element = dom.document.querySelector(selector);
@@ -152,7 +151,7 @@ abstract class Application {
152151
dom.Element selector(String selector) => element = _find(selector);
153152

154153
Application(): element = _find('[ng-app]', dom.window.document.documentElement) {
155-
traceInit(context);
154+
traceDetectWTF(context);
156155
modules.add(ngModule);
157156
ngModule..bind(VmTurnZone, toValue: zone)
158157
..bind(Application, toValue: this)
@@ -175,7 +174,7 @@ abstract class Application {
175174
}
176175

177176
Injector run() {
178-
var scope = traceEnter(_Application_run);
177+
var scope = traceEnter(Application_bootstrap);
179178
try {
180179
publishToJavaScript();
181180
return zone.run(() {

lib/change_detection/watch_group.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ library angular.watch_group;
22

33
import 'package:angular/change_detection/change_detection.dart';
44
import 'dart:collection';
5-
import 'package:angular/wtf.dart';
5+
import 'package:angular/ng_tracing.dart';
66

77
part 'linked_list.dart';
88
part 'ast.dart';
99
part 'prototype_map.dart';
1010

11-
var _WatchGroup_detect = traceCreateScope('WatchGroup#detect()');
12-
var _WatchGroup_fields = traceCreateScope('WatchGroup#field()');
13-
var _WatchGroup_field_handler = traceCreateScope('WatchGroup#field_handler()');
14-
var _WatchGroup_eval = traceCreateScope('WatchGroup#eval()');
15-
var _WatchGroup_reaction = traceCreateScope('WatchGroup#reaction()');
16-
1711
/**
1812
* A function that is notified of changes to the model.
1913
*
@@ -396,29 +390,27 @@ class RootWatchGroup extends WatchGroup {
396390
AvgStopwatch evalStopwatch,
397391
AvgStopwatch processStopwatch}) {
398392
// Process the Records from the change detector
399-
var sDetect = traceEnter(_WatchGroup_detect);
400-
var s = traceEnter(_WatchGroup_fields);
393+
var sDetect = traceEnter(ChangeDetector_check);
394+
var sFields = traceEnter(ChangeDetector_fields);
401395
Iterator<Record<_Handler>> changedRecordIterator =
402396
(_changeDetector as ChangeDetector<_Handler>).collectChanges(
403397
exceptionHandler:exceptionHandler,
404398
stopwatch: fieldStopwatch);
405-
traceLeave(s);
406399
if (processStopwatch != null) processStopwatch.start();
407-
s = traceEnter(_WatchGroup_field_handler);
408400
while (changedRecordIterator.moveNext()) {
409401
var record = changedRecordIterator.current;
410402
if (changeLog != null) changeLog(record.handler.expression,
411403
record.currentValue,
412404
record.previousValue);
413405
record.handler.onChange(record);
414406
}
415-
traceLeave(s);
407+
traceLeave(sFields);
416408
if (processStopwatch != null) processStopwatch.stop();
417409

418410
if (evalStopwatch != null) evalStopwatch.start();
419411
// Process our own function evaluations
420412
_EvalWatchRecord evalRecord = _evalWatchHead;
421-
s = traceEnter(_WatchGroup_eval);
413+
var sEval = traceEnter(ChangeDetector_eval);
422414
int evalCount = 0;
423415
while (evalRecord != null) {
424416
try {
@@ -434,14 +426,14 @@ class RootWatchGroup extends WatchGroup {
434426
evalRecord = evalRecord._nextEvalWatch;
435427
}
436428

437-
traceLeave(s);
429+
traceLeave(sEval);
438430
traceLeave(sDetect);
439431
if (evalStopwatch != null) evalStopwatch..stop()..increment(evalCount);
440432

441433
// Because the handler can forward changes between each other synchronously
442434
// We need to call reaction functions asynchronously. This processes the
443435
// asynchronous reaction function queue.
444-
s = traceEnter(_WatchGroup_reaction);
436+
var sReaction = traceEnter(ChangeDetector_reaction);
445437
int count = 0;
446438
if (processStopwatch != null) processStopwatch.start();
447439
Watch dirtyWatch = _dirtyWatchHead;
@@ -465,7 +457,7 @@ class RootWatchGroup extends WatchGroup {
465457
_dirtyWatchTail = null;
466458
root._removeCount = 0;
467459
}
468-
traceLeave(s);
460+
traceLeaveVal(sReaction, count);
469461
if (processStopwatch != null) processStopwatch..stop()..increment(count);
470462
return count;
471463
}
@@ -511,7 +503,12 @@ class Watch {
511503
void invoke() {
512504
if (_deleted || !_dirty) return;
513505
_dirty = false;
514-
reactionFn(_record.currentValue, _record.previousValue);
506+
var s = traceEnabled ? traceEnter1(ChangeDetector_invoke, expression) : null;
507+
try {
508+
reactionFn(_record.currentValue, _record.previousValue);
509+
} finally {
510+
if (traceEnabled) traceLeave(s);
511+
}
515512
}
516513

517514
void remove() {

lib/core/module_internal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:di/annotations.dart';
1111
import 'package:angular/core/parser/parser.dart';
1212
import 'package:angular/core/parser/lexer.dart';
1313
import 'package:angular/utils.dart';
14-
import 'package:angular/wtf.dart';
14+
import 'package:angular/ng_tracing.dart';
1515

1616
import 'package:angular/core/annotation_src.dart';
1717

lib/core/scope.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ part of angular.core_internal;
33
typedef EvalFunction0();
44
typedef EvalFunction1(context);
55

6-
var _Scope_apply = traceCreateScope('Scope#apply()');
7-
var _Scope_digest = traceCreateScope('Scope#digest()');
8-
var _Scope_flush = traceCreateScope('Scope#flush()');
9-
var _Scope_domWrite = traceCreateScope('Scope#domWrite()');
10-
var _Scope_domRead = traceCreateScope('Scope#domRead()');
11-
var _Scope_assert = traceCreateScope('Scope#assert()');
12-
var _Scope_runAsync = traceCreateScope('Scope#runAsync()');
13-
var _Scope_createChild = traceCreateScope('Scope#createChild()');
146
/**
157
* Injected into the listener function within [Scope.on] to provide event-specific details to the
168
* scope listener.
@@ -338,7 +330,7 @@ class Scope {
338330

339331
/// Creates a child [Scope] with the given [childContext]
340332
Scope createChild(Object childContext) {
341-
var s = traceEnter(_Scope_createChild);
333+
var s = traceEnter(Scope_createChild);
342334
assert(isAttached);
343335
var child = new Scope(childContext, rootScope, this,
344336
_readWriteGroup.newGroup(childContext),
@@ -746,7 +738,7 @@ class RootScope extends Scope {
746738
try {
747739
do {
748740
if (_domWriteHead != null) _stats.domWriteStart();
749-
var s = traceEnter(_Scope_domWrite);
741+
var s = traceEnter(Scope_domWrite);
750742
while (_domWriteHead != null) {
751743
try {
752744
_domWriteHead.fn();
@@ -766,7 +758,7 @@ class RootScope extends Scope {
766758
processStopwatch: _scopeStats.processStopwatch);
767759
}
768760
if (_domReadHead != null) _stats.domReadStart();
769-
s = traceEnter(_Scope_domRead);
761+
s = traceEnter(Scope_domRead);
770762
while (_domReadHead != null) {
771763
try {
772764
_domReadHead.fn();
@@ -823,7 +815,7 @@ class RootScope extends Scope {
823815
}
824816

825817
_runAsyncFns() {
826-
var s = traceEnter(_Scope_runAsync);
818+
var s = traceEnter(Scope_execAsync);
827819
var count = 0;
828820
while (_runAsyncHead != null) {
829821
try {
@@ -865,10 +857,10 @@ class RootScope extends Scope {
865857
_state = to;
866858
if (_state_wtf_scope != null) traceLeave(_state_wtf_scope);
867859
var wtfScope = null;
868-
if (to == STATE_APPLY) wtfScope = _Scope_apply;
869-
else if (to == STATE_DIGEST) wtfScope = _Scope_digest;
870-
else if (to == STATE_FLUSH) wtfScope = _Scope_flush;
871-
else if (to == STATE_FLUSH_ASSERT) wtfScope = _Scope_assert;
860+
if (to == STATE_APPLY) wtfScope = Scope_apply;
861+
else if (to == STATE_DIGEST) wtfScope = Scope_digest;
862+
else if (to == STATE_FLUSH) wtfScope = Scope_flush;
863+
else if (to == STATE_FLUSH_ASSERT) wtfScope = Scope_assert;
872864
_state_wtf_scope = wtfScope == null ? null : traceEnter(wtfScope);
873865
}
874866
}

lib/core/zone.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ class LongStackTrace {
3939
}
4040
}
4141

42-
var _VmTurnZone_onRunBase = traceCreateScope('VmTurnZone#onRun()');
43-
var _VmTurnZone_onScheduleMicrotask = traceCreateScope('VmTurnZone#onScheduleMicrotask()');
44-
4542
/**
4643
* A [Zone] wrapper that lets you schedule tasks after its private microtask
4744
* queue is exhausted but before the next "turn", i.e. event loop iteration.
@@ -92,7 +89,7 @@ class VmTurnZone {
9289
var _currentlyInTurn = false;
9390

9491
dynamic _onRunBase(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn()) {
95-
var scope = traceEnter(_VmTurnZone_onRunBase);
92+
var scope = traceEnter(VmTurnZone_run);
9693
_runningInTurn++;
9794
try {
9895
if (!_currentlyInTurn) {
@@ -120,7 +117,7 @@ class VmTurnZone {
120117
_onRunBase(self, delegate, zone, () => delegate.runUnary(zone, fn, args));
121118

122119
void _onScheduleMicrotask(async.Zone self, async.ZoneDelegate delegate, async.Zone zone, fn()) {
123-
var s = traceEnter(_VmTurnZone_onScheduleMicrotask);
120+
var s = traceEnter(VmTurnZone_scheduleMicrotask);
124121
try {
125122
onScheduleMicrotask(() => delegate.run(zone, fn));
126123
if (_runningInTurn == 0 && !_inFinishTurn) _finishTurn(zone, delegate);

lib/core_dom/compiler.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
part of angular.core.dom_internal;
22

3-
var _Compiler_call = traceCreateScope('Compiler#call()');
4-
var _Compiler_subTemplate = traceCreateScope('Compiler#subTemplate()');
53

64
@Injectable()
75
class Compiler implements Function {
@@ -11,7 +9,7 @@ class Compiler implements Function {
119
Compiler(this._perf, this._expando);
1210

1311
ViewFactory call(List<dom.Node> elements, DirectiveMap directives) {
14-
var s = traceEnter(_Compiler_call);
12+
var s = traceEnter(Compiler_compile);
1513
var timerId;
1614
assert((timerId = _perf.startTimer('ng.compile', _html(elements))) != false);
1715
final elementBinders = <TaggedElementBinder>[];
@@ -141,7 +139,7 @@ class Compiler implements Function {
141139
DirectiveRef directiveRef,
142140
ElementBinder transcludedElementBinder,
143141
DirectiveMap directives) {
144-
var s = traceEnter(_Compiler_subTemplate);
142+
var s = traceEnter(Compiler_template);
145143
var anchorName = directiveRef.annotation.selector +
146144
(directiveRef.value != null ? '=' + directiveRef.value : '');
147145

lib/core_dom/element_binder.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
part of angular.core.dom_internal;
22

3-
var _ElementBinder_directive = traceCreateScope('ElementBinder#createDirective(ascii name)');
4-
var _ElementBinder_setupBindings = traceCreateScope('ElementBinder#setupBindings(ascii name)');
53

64
class TemplateElementBinder extends ElementBinder {
75
final DirectiveRef template;
@@ -193,19 +191,13 @@ class ElementBinder {
193191
for(var i = 0; i < _usableDirectiveRefs.length; i++) {
194192
DirectiveRef ref = _usableDirectiveRefs[i];
195193
var key = ref.typeKey;
196-
var wtfArgs = wtfEnabled ? [ref.typeKey.toString()] : null;
194+
var directiveName = traceEnabled ? ref.typeKey.toString() : null;
197195
if (identical(key, TEXT_MUSTACHE_KEY) || identical(key, ATTR_MUSTACHE_KEY)) continue;
198196

199-
s = traceEnter(_ElementBinder_directive, wtfArgs);
197+
s = traceEnter1(Directive_create, directiveName);
200198
var directive;
201199
try {
202200
directive = directiveInjector.getByKey(ref.typeKey);
203-
} finally {
204-
traceLeave(s);
205-
}
206-
207-
s = traceEnter(_ElementBinder_setupBindings, wtfArgs);
208-
try {
209201
if (ref.annotation is Controller) {
210202
scope.parentScope.context[(ref.annotation as Controller).publishAs] = directive;
211203
}

lib/core_dom/http.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class Http {
445445
cache,
446446
timeout
447447
}) {
448-
var range = wtfEnabled ? traceAsyncStart('http:$method', url) : null;
448+
var range = traceEnabled ? traceAsyncStart('http:$method', url) : null;
449449
if (timeout != null) {
450450
throw ['timeout not implemented'];
451451
}
@@ -545,7 +545,7 @@ class Http {
545545
var result = chainResult is async.Future
546546
? chainResult
547547
: new async.Future.value(chainResult);
548-
if (wtfEnabled) {
548+
if (traceEnabled) {
549549
return new async.Future(() {
550550
traceAsyncEnd(range);
551551
return result;

lib/core_dom/module_internal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export 'package:angular/core_dom/directive_injector.dart' show DirectiveInjector
2222
import 'package:angular/change_detection/watch_group.dart' show Watch, PrototypeMap;
2323
import 'package:angular/change_detection/ast_parser.dart';
2424
import 'package:angular/core/registry.dart';
25-
import 'package:angular/wtf.dart';
25+
import 'package:angular/ng_tracing.dart';
2626

2727
import 'package:angular/directive/module.dart' show NgBaseCss;
2828
import 'dart:collection';

lib/core_dom/shadow_dom_component_factory.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
part of angular.core.dom_internal;
22

3-
var _ComponentFactory_call = traceCreateScope('ComponentFactory#call()');
4-
var _ComponentFactory_styles = traceCreateScope('ComponentFactory#styles()');
5-
63
abstract class ComponentFactory {
74
BoundComponentFactory bind(DirectiveRef ref, directives);
85
}
@@ -134,7 +131,7 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
134131
Function call(dom.Element element) {
135132
return (DirectiveInjector injector, Scope scope, NgBaseCss baseCss,
136133
EventHandler eventHandler) {
137-
var s = traceEnter(_ComponentFactory_call);
134+
var s = traceEnter(View_createComponent);
138135
try {
139136
var shadowScope = scope.createChild(new HashMap()); // Isolate
140137
ComponentDirectiveInjector shadowInjector;
@@ -203,7 +200,7 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
203200
_insertCss(List<dom.StyleElement> cssList,
204201
dom.ShadowRoot shadowRoot,
205202
[dom.Node insertBefore = null]) {
206-
var s = traceEnter(_ComponentFactory_styles);
203+
var s = traceEnter(View_styles);
207204
for(int i = 0; i < cssList.length; i++) {
208205
var styleElement = cssList[i];
209206
if (styleElement != null) {

0 commit comments

Comments
 (0)