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:
parent
7ae23adaff
commit
89f32f808f
|
@ -19,6 +19,12 @@ import 'package:barback/barback.dart';
|
||||||
///
|
///
|
||||||
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
|
/// The returned value wraps the [NgDepsModel] at `assetId` as well as these
|
||||||
/// created objects.
|
/// 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(
|
Future<CompileDataResults> createCompileData(
|
||||||
AssetReader reader,
|
AssetReader reader,
|
||||||
AssetId assetId,
|
AssetId assetId,
|
||||||
|
@ -65,9 +71,17 @@ class _CompileDataCreator {
|
||||||
NgDepsModel get ngDeps => ngMeta.ngDeps;
|
NgDepsModel get ngDeps => ngMeta.ngDeps;
|
||||||
|
|
||||||
Future<CompileDataResults> createCompileData() async {
|
Future<CompileDataResults> createCompileData() async {
|
||||||
if (ngDeps == null || ngDeps.reflectables == null) {
|
var hasTemplate = ngDeps != null &&
|
||||||
return new CompileDataResults._(ngMeta, const {});
|
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 =
|
final compileData =
|
||||||
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};
|
<ReflectionInfoModel, NormalizedComponentWithViewDirectives>{};
|
||||||
|
|
|
@ -22,9 +22,17 @@ import 'reflection/processor.dart' as reg;
|
||||||
import 'reflection/reflection_capabilities.dart';
|
import 'reflection/reflection_capabilities.dart';
|
||||||
import 'compile_data_creator.dart';
|
import 'compile_data_creator.dart';
|
||||||
|
|
||||||
/// Reads the `.ng_deps.dart` file represented by `assetId` and parses any
|
/// Generates `.ng_deps.dart` files to initialize the Angular2 system.
|
||||||
/// Angular 2 `View` annotations it declares to generate `getter`s,
|
///
|
||||||
/// `setter`s, and `method`s that would otherwise be reflectively accessed.
|
/// 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.
|
/// This method assumes a {@link DomAdapter} has been registered.
|
||||||
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
Future<Outputs> processTemplates(AssetReader reader, AssetId assetId,
|
||||||
|
|
Loading…
Reference in New Issue