Skip to content

Commit e3548b4

Browse files
committed
feat(ElementInjector): implement ElementInjector
1 parent ea0df35 commit e3548b4

27 files changed

+866
-69
lines changed

gulpfile.js

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
var shell = require('gulp-shell');
12
var gulp = require('gulp');
23
var rename = require('gulp-rename');
34
var watch = require('gulp-watch');
45
var mergeStreams = require('event-stream').merge;
6+
var es = require('event-stream');
57
var connect = require('gulp-connect');
68
var clean = require('gulp-rimraf');
79
var runSequence = require('run-sequence');
@@ -225,22 +227,58 @@ gulp.task('analyze/dartanalyzer', function(done) {
225227

226228

227229
// ------------------
228-
// BENCHMARKS
230+
// BENCHMARKS JS
229231

230-
var benchmarksBuildPath = 'build/benchpress';
231-
var benchmarksCompiledJsPath = 'build/js/benchmarks/lib';
232-
233-
gulp.task('benchmarks/build.benchpress', function () {
232+
gulp.task('benchmarks/build.benchpress.js', function () {
234233
benchpress.build({
235-
benchmarksPath: benchmarksCompiledJsPath,
236-
buildPath: benchmarksBuildPath
234+
benchmarksPath: 'build/js/benchmarks/lib',
235+
buildPath: 'build/benchpress/js'
237236
})
238237
});
239238

240-
gulp.task('benchmarks/build', function() {
239+
gulp.task('benchmarks/build.js', function() {
241240
runSequence(
242241
['jsRuntime/build', 'modules/build.prod.js'],
243-
'benchmarks/build.benchpress'
242+
'benchmarks/build.benchpress.js'
243+
);
244+
});
245+
246+
247+
// ------------------
248+
// BENCHMARKS DART
249+
250+
gulp.task('benchmarks/build.dart2js.dart', function () {
251+
return gulp.src([
252+
"build/dart/benchmarks/lib/**/benchmark.dart"
253+
]).pipe(shell(['dart2js --package-root="build/dart/benchmarks/packages" -o "<%= file.path %>.js" <%= file.path %>']));
254+
});
255+
256+
gulp.task('benchmarks/create-bpconf.dart', function () {
257+
var bpConfContent = "module.exports = function(c) {c.set({scripts: [{src: 'benchmark.dart.js'}]});}";
258+
var createBpConfJs = es.map(function(file, cb) {
259+
var dir = path.dirname(file.path);
260+
fs.writeFileSync(path.join(dir, "bp.conf.js"), bpConfContent);
261+
cb();
262+
});
263+
264+
return gulp.src([
265+
"build/dart/benchmarks/lib/**/benchmark.dart"
266+
]).pipe(createBpConfJs);
267+
});
268+
269+
gulp.task('benchmarks/build.benchpress.dart', function () {
270+
benchpress.build({
271+
benchmarksPath: 'build/dart/benchmarks/lib',
272+
buildPath: 'build/benchpress/dart'
273+
})
274+
});
275+
276+
gulp.task('benchmarks/build.dart', function() {
277+
runSequence(
278+
'modules/build.dart',
279+
'benchmarks/build.dart2js.dart',
280+
'benchmarks/create-bpconf.dart',
281+
'benchmarks/build.benchpress.dart'
244282
);
245283
});
246284

modules/benchmarks/pubspec.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: bnehcmarks
2+
environment:
3+
sdk: '>=1.4.0'
4+
dependencies:
5+
facade:
6+
path: ../facade
7+
di:
8+
path: ../di
9+
core:
10+
path: ../core
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library injector_get_benchmark;
2+
3+
import './injector_instantiate_benchmark.dart' as b;
4+
import 'dart:js' as js;
5+
6+
main () {
7+
js.context['benchmarkSteps'].add(new js.JsObject.jsify({
8+
"name": "Injector.instantiate",
9+
"fn": new js.JsFunction.withThis((_) => b.run())
10+
}));
11+
}

modules/benchmarks/src/di/injector_instantiate_benchmark.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export function run () {
1010
var child = injector.createChild([E]);
1111
child.get(E);
1212
}
13-
14-
console.log(count)
1513
}
1614

1715
class A {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library element_injector_benchmark;
2+
3+
import './instantiate_benchmark.dart' as ib;
4+
import 'dart:js' as js;
5+
6+
main () {
7+
js.context['benchmarkSteps'].add(new js.JsObject.jsify({
8+
"name": "ElementInjector.instantiate + instantiateDirectives",
9+
"fn": new js.JsFunction.withThis((_) => ib.run())
10+
}));
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
System.import('benchmarks/element_injector/instantiate_benchmark').then(function (bm) {
2+
window.benchmarkSteps.push({name: 'ElementInjector.instantiate + instantiateDirectives', fn: bm.run});
3+
}, console.log.bind(console));
4+
5+
System.import('benchmarks/element_injector/instantiate_directive_benchmark').then(function (bm) {
6+
window.benchmarkSteps.push({name: 'ElementInjector.instantiateDirectives', fn: bm.run});
7+
}, console.log.bind(console));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = function(config) {
2+
config.set({
3+
scripts: [
4+
{src: '/js/traceur-runtime.js'},
5+
{src: '/js/es6-module-loader-sans-promises.src.js'},
6+
{src: '/js/extension-register.js'},
7+
{src: 'register_system.js'},
8+
{src: 'benchmark.js'}
9+
]
10+
});
11+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Injector} from 'di/di';
2+
import {ProtoElementInjector} from 'core/compiler/element_injector';
3+
4+
var count = 0;
5+
6+
export function run () {
7+
var appInjector = new Injector([]);
8+
9+
var bindings = [A, B, C];
10+
var proto = new ProtoElementInjector(null, bindings, []);
11+
for (var i = 0; i < 20000; ++i) {
12+
var ei = proto.instantiate();
13+
ei.instantiateDirectives(appInjector);
14+
}
15+
}
16+
17+
class A {
18+
constructor() {
19+
count++;
20+
}
21+
}
22+
23+
class B {
24+
constructor() {
25+
count++;
26+
}
27+
}
28+
29+
class C {
30+
constructor(a:A, b:B) {
31+
count++;
32+
}
33+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {Injector} from 'di/di';
2+
import {ProtoElementInjector} from 'core/compiler/element_injector';
3+
4+
var count = 0;
5+
6+
export function run () {
7+
var appInjector = new Injector([]);
8+
9+
var bindings = [A, B, C];
10+
var proto = new ProtoElementInjector(null, bindings, []);
11+
var ei = proto.instantiate();
12+
13+
for (var i = 0; i < 20000; ++i) {
14+
ei.clearDirectives();
15+
ei.instantiateDirectives(appInjector);
16+
}
17+
}
18+
19+
class A {
20+
constructor() {
21+
count++;
22+
}
23+
}
24+
25+
class B {
26+
constructor() {
27+
count++;
28+
}
29+
}
30+
31+
class C {
32+
constructor(a:A, b:B) {
33+
count++;
34+
}
35+
}

modules/benchmarks/src/element_injector/main.html

Whitespace-only changes.

0 commit comments

Comments
 (0)