Skip to content

Commit f6ebaf7

Browse files
committed
perf: force GC on profiles
1 parent abf0340 commit f6ebaf7

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

modules/benchmarks/src/tree/tree_benchmark.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TemplateLoader} from 'core/compiler/template_loader';
88
import {LifeCycle} from 'core/life_cycle/life_cycle';
99

1010
import {reflector} from 'reflection/reflection';
11-
import {DOM, document, window, Element} from 'facade/dom';
11+
import {DOM, document, window, Element, gc} from 'facade/dom';
1212
import {isPresent} from 'facade/lang';
1313

1414
var MAX_DEPTH = 9;
@@ -137,18 +137,29 @@ export function main() {
137137

138138
function profile(create, destroy, name) {
139139
return function(_) {
140-
window.console.profile(name);
140+
window.console.profile(name + ' w GC');
141141
var duration = 0;
142-
var downCount = 200;
143142
var count = 0;
144-
while(downCount--) {
143+
while(count++ < 150) {
144+
gc();
145145
var start = window.performance.now();
146146
create(_);
147147
duration += window.performance.now() - start;
148148
destroy(_);
149-
count++;
150149
}
151-
window.console.profileEnd(name);
150+
window.console.profileEnd(name + ' w GC');
151+
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
152+
153+
window.console.profile(name + ' w/o GC');
154+
duration = 0;
155+
count = 0;
156+
while(count++ < 150) {
157+
var start = window.performance.now();
158+
create(_);
159+
duration += window.performance.now() - start;
160+
destroy(_);
161+
}
162+
window.console.profileEnd(name + ' w/o GC');
152163
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
153164
};
154165
}
@@ -227,6 +238,7 @@ var BASELINE_IF_TEMPLATE = DOM.createTemplate(
227238
// http://jsperf.com/nextsibling-vs-childnodes
228239

229240
class BaseLineTreeComponent {
241+
element:Element;
230242
value:BaseLineInterpolation;
231243
left:BaseLineIf;
232244
right:BaseLineIf;

modules/facade/src/dom.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library angular.core.facade.dom;
22

33
import 'dart:html';
4-
import 'dart:js' show JsObject;
4+
import 'dart:js' show JsObject, context;
55

66
export 'dart:html' show DocumentFragment, Node, Element, TemplateElement, Text, document, location, window;
77

@@ -11,6 +11,15 @@ class IdentitySanitizer implements NodeTreeSanitizer {
1111
void sanitizeTree(Node node) {}
1212
}
1313

14+
var _window = context['window'];
15+
var _gc = context['gc'];
16+
17+
gc() {
18+
if (_gc != null) {
19+
_gc.apply(const []);
20+
}
21+
}
22+
1423
final identitySanitizer = new IdentitySanitizer();
1524

1625
class DOM {

modules/facade/src/dom.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export var Element = window.HTMLElement;
77
export var TemplateElement = window.HTMLTemplateElement;
88
export var document = window.document;
99
export var location = window.location;
10+
export var gc = window.gc ? () => window.gc() : () => null;
1011

1112
import {List, MapWrapper, ListWrapper} from 'facade/collection';
1213

0 commit comments

Comments
 (0)