Skip to content

Commit 89f32f8

Browse files
Tim Blasitbosch
authored andcommitted
perf(dart/transform): Avoid unnecessary reads for files with no view
In the `TemplateCompiler` phase, avoid reading in the `.ng_meta.json` files of imported libraries when we can determine that the file we are processing does not define any `View`s. Closes angular#6183
1 parent 7ae23ad commit 89f32f8

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

modules_dart/transform/lib/src/transform/template_compiler/compile_data_creator.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import 'package:barback/barback.dart';
1919
///
2020
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
2121
/// created objects.
22+
///
23+
/// `platformDirectives` is an optional [List] containing names of [Directive]s
24+
/// which should be available to all [View]s in this app.
25+
///
26+
/// `platformPipes` is an optional [List] containing names of [Pipe]s which
27+
/// should be available to all [View]s in this app.
2228
Future<CompileDataResults> createCompileData(
2329
AssetReader reader,
2430
AssetId assetId,
@@ -65,9 +71,17 @@ class _CompileDataCreator {
6571
NgDepsModel get ngDeps => ngMeta.ngDeps;
6672

6773
Future<CompileDataResults> createCompileData() async {
68-
if (ngDeps == null || ngDeps.reflectables == null) {
69-
return new CompileDataResults._(ngMeta, const {});
70-
}
74+
var hasTemplate = ngDeps != null &&
75+
ngDeps.reflectables != null &&
76+
ngDeps.reflectables.any((reflectable) {
77+
if (ngMeta.types.containsKey(reflectable.name)) {
78+
final metadata = ngMeta.types[reflectable.name];
79+
return metadata is CompileDirectiveMetadata &&
80+
metadata.template != null;
81+
}
82+
return false;
83+
});
84+
if (!hasTemplate) return new CompileDataResults._(ngMeta, const {});
7185

7286
final compileData =
7387
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};

modules_dart/transform/lib/src/transform/template_compiler/generator.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ import 'reflection/processor.dart' as reg;
2222
import 'reflection/reflection_capabilities.dart';
2323
import 'compile_data_creator.dart';
2424

25-
/// Reads the `.ng_deps.dart` file represented by `assetId` and parses any
26-
/// Angular 2 `View` annotations it declares to generate `getter`s,
27-
/// `setter`s, and `method`s that would otherwise be reflectively accessed.
25+
/// Generates `.ng_deps.dart` files to initialize the Angular2 system.
26+
///
27+
/// Processes the `.ng_summary.json` file represented by `assetId`
28+
/// `createCompileData`.
29+
/// Uses the resulting `NgMeta` object to generate
30+
/// `getter`s, `setter`s, and `method`s that would otherwise need to be
31+
/// reflectively accessed.
32+
/// Passes the resulting `NormalizedComponentWithViewDirectives` instances
33+
/// to the `TemplateCompiler` to generate compiled template(s).
34+
/// Uses the resulting `NgDeps` object to generate a .ng_deps.dart file which
35+
/// initializes the Angular2 reflective system.
2836
///
2937
/// This method assumes a {@link DomAdapter} has been registered.
3038
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,

0 commit comments

Comments
 (0)