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 #6183
This commit is contained in:
Tim Blasi 2015-12-30 14:00:12 -08:00 committed by Tobias Bosch
parent 7ae23adaff
commit 89f32f808f
2 changed files with 28 additions and 6 deletions

View File

@ -19,6 +19,12 @@ import 'package:barback/barback.dart';
///
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
/// created objects.
///
/// `platformDirectives` is an optional [List] containing names of [Directive]s
/// which should be available to all [View]s in this app.
///
/// `platformPipes` is an optional [List] containing names of [Pipe]s which
/// should be available to all [View]s in this app.
Future<CompileDataResults> createCompileData(
AssetReader reader,
AssetId assetId,
@ -65,9 +71,17 @@ class _CompileDataCreator {
NgDepsModel get ngDeps => ngMeta.ngDeps;
Future<CompileDataResults> createCompileData() async {
if (ngDeps == null || ngDeps.reflectables == null) {
return new CompileDataResults._(ngMeta, const {});
var hasTemplate = ngDeps != null &&
ngDeps.reflectables != null &&
ngDeps.reflectables.any((reflectable) {
if (ngMeta.types.containsKey(reflectable.name)) {
final metadata = ngMeta.types[reflectable.name];
return metadata is CompileDirectiveMetadata &&
metadata.template != null;
}
return false;
});
if (!hasTemplate) return new CompileDataResults._(ngMeta, const {});
final compileData =
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};

View File

@ -22,9 +22,17 @@ import 'reflection/processor.dart' as reg;
import 'reflection/reflection_capabilities.dart';
import 'compile_data_creator.dart';
/// Reads the `.ng_deps.dart` file represented by `assetId` and parses any
/// Angular 2 `View` annotations it declares to generate `getter`s,
/// `setter`s, and `method`s that would otherwise be reflectively accessed.
/// Generates `.ng_deps.dart` files to initialize the Angular2 system.
///
/// Processes the `.ng_summary.json` file represented by `assetId`
/// `createCompileData`.
/// Uses the resulting `NgMeta` object to generate
/// `getter`s, `setter`s, and `method`s that would otherwise need to be
/// reflectively accessed.
/// Passes the resulting `NormalizedComponentWithViewDirectives` instances
/// to the `TemplateCompiler` to generate compiled template(s).
/// Uses the resulting `NgDeps` object to generate a .ng_deps.dart file which
/// initializes the Angular2 reflective system.
///
/// This method assumes a {@link DomAdapter} has been registered.
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,