feat(dart/transform): Do not declare outputs
Experience shows that for large projects, declaring transformer outputs can cause ~10x slowdown. Remove output declarations to avoid this.
This commit is contained in:
parent
1caccc410a
commit
27ead8c883
@ -16,7 +16,7 @@ import 'generator.dart';
|
|||||||
///
|
///
|
||||||
/// These setters are registered in the same `setupReflection` function with
|
/// These setters are registered in the same `setupReflection` function with
|
||||||
/// the `registerType` calls.
|
/// the `registerType` calls.
|
||||||
class BindGenerator extends Transformer implements DeclaringTransformer {
|
class BindGenerator extends Transformer {
|
||||||
final TransformerOptions options;
|
final TransformerOptions options;
|
||||||
|
|
||||||
BindGenerator(this.options);
|
BindGenerator(this.options);
|
||||||
@ -24,19 +24,12 @@ class BindGenerator extends Transformer implements DeclaringTransformer {
|
|||||||
@override
|
@override
|
||||||
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
|
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
await log.initZoned(transform, () async {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var transformedCode = await createNgSettersAndGetters(reader, primaryId);
|
var transformedCode = await createNgSettersAndGetters(reader, primaryId);
|
||||||
transform.consumePrimary();
|
|
||||||
transform.addOutput(new Asset.fromString(
|
transform.addOutput(new Asset.fromString(
|
||||||
primaryId, formatter.format(transformedCode, uri: primaryId.path)));
|
primaryId, formatter.format(transformedCode, uri: primaryId.path)));
|
||||||
});
|
});
|
||||||
|
@ -13,7 +13,7 @@ import 'rewriter.dart';
|
|||||||
/// Transformer responsible for rewriting deferred library loads to enable
|
/// Transformer responsible for rewriting deferred library loads to enable
|
||||||
/// initializing the reflector in a deferred way to keep the code with the
|
/// initializing the reflector in a deferred way to keep the code with the
|
||||||
/// deferred library.
|
/// deferred library.
|
||||||
class DeferredRewriter extends Transformer implements DeclaringTransformer {
|
class DeferredRewriter extends Transformer {
|
||||||
final TransformerOptions options;
|
final TransformerOptions options;
|
||||||
|
|
||||||
DeferredRewriter(this.options);
|
DeferredRewriter(this.options);
|
||||||
@ -22,23 +22,14 @@ class DeferredRewriter extends Transformer implements DeclaringTransformer {
|
|||||||
bool isPrimary(AssetId id) =>
|
bool isPrimary(AssetId id) =>
|
||||||
id.extension.endsWith('dart') && !id.path.endsWith(DEPS_EXTENSION);
|
id.extension.endsWith('dart') && !id.path.endsWith(DEPS_EXTENSION);
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
await log.initZoned(transform, () async {
|
||||||
var asset = transform.primaryInput;
|
var asset = transform.primaryInput;
|
||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var transformedCode = await rewriteDeferredLibraries(reader, asset.id);
|
var transformedCode = await rewriteDeferredLibraries(reader, asset.id);
|
||||||
transform.consumePrimary();
|
|
||||||
if (transformedCode != null) {
|
if (transformedCode != null) {
|
||||||
transform.addOutput(new Asset.fromString(asset.id, transformedCode));
|
transform.addOutput(new Asset.fromString(asset.id, transformedCode));
|
||||||
} else {
|
|
||||||
transform.addOutput(asset);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,22 +20,12 @@ import 'ng_meta_linker.dart';
|
|||||||
///
|
///
|
||||||
/// See `common/ng_meta.dart` for the JSON format of these files are serialized
|
/// See `common/ng_meta.dart` for the JSON format of these files are serialized
|
||||||
/// to.
|
/// to.
|
||||||
class DirectiveMetadataLinker extends Transformer
|
class DirectiveMetadataLinker extends Transformer {
|
||||||
implements DeclaringTransformer {
|
|
||||||
final _encoder = const JsonEncoder.withIndent(' ');
|
final _encoder = const JsonEncoder.withIndent(' ');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isPrimary(AssetId id) => id.path.endsWith(META_EXTENSION);
|
bool isPrimary(AssetId id) => id.path.endsWith(META_EXTENSION);
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
// TODO(kegluenq): We should consume this, but doing so causes barback to
|
|
||||||
// incorrectly determine what assets are available in this phase.
|
|
||||||
// transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
transform.declareOutput(_depsAssetId(transform.primaryId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) {
|
Future apply(Transform transform) {
|
||||||
return log.initZoned(transform, () {
|
return log.initZoned(transform, () {
|
||||||
@ -43,8 +33,6 @@ class DirectiveMetadataLinker extends Transformer
|
|||||||
|
|
||||||
return linkDirectiveMetadata(
|
return linkDirectiveMetadata(
|
||||||
new AssetReader.fromTransform(transform), primaryId).then((ngMeta) {
|
new AssetReader.fromTransform(transform), primaryId).then((ngMeta) {
|
||||||
// See above
|
|
||||||
// transform.consumePrimary();
|
|
||||||
if (ngMeta != null) {
|
if (ngMeta != null) {
|
||||||
if (!ngMeta.types.isEmpty || !ngMeta.aliases.isEmpty) {
|
if (!ngMeta.types.isEmpty || !ngMeta.aliases.isEmpty) {
|
||||||
transform.addOutput(new Asset.fromString(
|
transform.addOutput(new Asset.fromString(
|
||||||
|
@ -21,7 +21,7 @@ import 'rewriter.dart';
|
|||||||
///
|
///
|
||||||
/// This transformer is the first phase in a two-phase transform. It should
|
/// This transformer is the first phase in a two-phase transform. It should
|
||||||
/// be followed by {@link DirectiveLinker}.
|
/// be followed by {@link DirectiveLinker}.
|
||||||
class DirectiveProcessor extends Transformer implements DeclaringTransformer {
|
class DirectiveProcessor extends Transformer {
|
||||||
final TransformerOptions options;
|
final TransformerOptions options;
|
||||||
final _encoder = const JsonEncoder.withIndent(' ');
|
final _encoder = const JsonEncoder.withIndent(' ');
|
||||||
|
|
||||||
@ -30,14 +30,6 @@ class DirectiveProcessor extends Transformer implements DeclaringTransformer {
|
|||||||
@override
|
@override
|
||||||
bool isPrimary(AssetId id) => id.extension.endsWith('dart');
|
bool isPrimary(AssetId id) => id.extension.endsWith('dart');
|
||||||
|
|
||||||
/// We don't always output these, but providing a superset of our outputs
|
|
||||||
/// should be safe. Barback will just have to wait until `apply` finishes to
|
|
||||||
/// determine that one or the other will not be emitted.
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.declareOutput(_ngMetaAssetId(transform.primaryId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
Html5LibDomAdapter.makeCurrent();
|
Html5LibDomAdapter.makeCurrent();
|
||||||
|
@ -17,7 +17,7 @@ import 'package:barback/barback.dart';
|
|||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
|
|
||||||
/// Processes .dart files and inlines `templateUrl` and styleUrls` values.
|
/// Processes .dart files and inlines `templateUrl` and styleUrls` values.
|
||||||
class InlinerForTest extends Transformer implements DeclaringTransformer {
|
class InlinerForTest extends Transformer {
|
||||||
final DartFormatter _formatter;
|
final DartFormatter _formatter;
|
||||||
final AnnotationMatcher _annotationMatcher;
|
final AnnotationMatcher _annotationMatcher;
|
||||||
|
|
||||||
@ -28,17 +28,10 @@ class InlinerForTest extends Transformer implements DeclaringTransformer {
|
|||||||
@override
|
@override
|
||||||
bool isPrimary(AssetId id) => id.extension.endsWith('dart');
|
bool isPrimary(AssetId id) => id.extension.endsWith('dart');
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
return initZoned(transform, () async {
|
return initZoned(transform, () async {
|
||||||
var primaryId = transform.primaryInput.id;
|
var primaryId = transform.primaryInput.id;
|
||||||
transform.consumePrimary();
|
|
||||||
var inlinedCode = await inline(new AssetReader.fromTransform(transform),
|
var inlinedCode = await inline(new AssetReader.fromTransform(transform),
|
||||||
primaryId, _annotationMatcher);
|
primaryId, _annotationMatcher);
|
||||||
if (inlinedCode == null || inlinedCode.isEmpty) {
|
if (inlinedCode == null || inlinedCode.isEmpty) {
|
||||||
|
@ -19,7 +19,7 @@ import 'remove_reflection_capabilities.dart';
|
|||||||
/// have already been run and that a .ng_deps.dart file has been generated for
|
/// have already been run and that a .ng_deps.dart file has been generated for
|
||||||
/// {@link options.entryPoint}. The instantiation of {@link ReflectionCapabilities} is
|
/// {@link options.entryPoint}. The instantiation of {@link ReflectionCapabilities} is
|
||||||
/// replaced by calling `setupReflection` in that .ng_deps.dart file.
|
/// replaced by calling `setupReflection` in that .ng_deps.dart file.
|
||||||
class ReflectionRemover extends Transformer implements DeclaringTransformer {
|
class ReflectionRemover extends Transformer {
|
||||||
final TransformerOptions options;
|
final TransformerOptions options;
|
||||||
|
|
||||||
ReflectionRemover(this.options);
|
ReflectionRemover(this.options);
|
||||||
@ -28,12 +28,6 @@ class ReflectionRemover extends Transformer implements DeclaringTransformer {
|
|||||||
bool isPrimary(AssetId id) => options.entryPointGlobs != null &&
|
bool isPrimary(AssetId id) => options.entryPointGlobs != null &&
|
||||||
options.entryPointGlobs.any((g) => g.matches(id.path));
|
options.entryPointGlobs.any((g) => g.matches(id.path));
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
await log.initZoned(transform, () async {
|
||||||
@ -51,7 +45,6 @@ class ReflectionRemover extends Transformer implements DeclaringTransformer {
|
|||||||
var transformedCode = await removeReflectionCapabilities(
|
var transformedCode = await removeReflectionCapabilities(
|
||||||
new AssetReader.fromTransform(transform), primaryId,
|
new AssetReader.fromTransform(transform), primaryId,
|
||||||
mirrorMode: mirrorMode, writeStaticInit: writeStaticInit);
|
mirrorMode: mirrorMode, writeStaticInit: writeStaticInit);
|
||||||
transform.consumePrimary();
|
|
||||||
transform.addOutput(new Asset.fromString(primaryId, transformedCode));
|
transform.addOutput(new Asset.fromString(primaryId, transformedCode));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import 'package:barback/barback.dart';
|
|||||||
import 'processor.dart';
|
import 'processor.dart';
|
||||||
|
|
||||||
/// Pre-compiles CSS stylesheet files to Dart code for Angular 2.
|
/// Pre-compiles CSS stylesheet files to Dart code for Angular 2.
|
||||||
class StylesheetCompiler extends Transformer implements DeclaringTransformer {
|
class StylesheetCompiler extends Transformer {
|
||||||
StylesheetCompiler();
|
StylesheetCompiler();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -20,12 +20,6 @@ class StylesheetCompiler extends Transformer implements DeclaringTransformer {
|
|||||||
return id.path.endsWith(CSS_EXTENSION);
|
return id.path.endsWith(CSS_EXTENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.declareOutput(nonShimmedStylesheetAssetId(transform.primaryId));
|
|
||||||
transform.declareOutput(shimmedStylesheetAssetId(transform.primaryId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
await log.initZoned(transform, () async {
|
||||||
|
@ -18,7 +18,7 @@ import 'generator.dart';
|
|||||||
/// extracting information about what reflection is necessary to render and
|
/// extracting information about what reflection is necessary to render and
|
||||||
/// use that template. It then generates code in place of those reflective
|
/// use that template. It then generates code in place of those reflective
|
||||||
/// accesses.
|
/// accesses.
|
||||||
class TemplateCompiler extends Transformer implements DeclaringTransformer {
|
class TemplateCompiler extends Transformer {
|
||||||
final TransformerOptions options;
|
final TransformerOptions options;
|
||||||
|
|
||||||
TemplateCompiler(this.options);
|
TemplateCompiler(this.options);
|
||||||
@ -26,13 +26,6 @@ class TemplateCompiler extends Transformer implements DeclaringTransformer {
|
|||||||
@override
|
@override
|
||||||
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
|
bool isPrimary(AssetId id) => id.path.endsWith(DEPS_EXTENSION);
|
||||||
|
|
||||||
@override
|
|
||||||
declareOutputs(DeclaringTransform transform) {
|
|
||||||
transform.consumePrimary();
|
|
||||||
transform.declareOutput(transform.primaryId);
|
|
||||||
transform.declareOutput(templatesAssetId(transform.primaryId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future apply(Transform transform) async {
|
Future apply(Transform transform) async {
|
||||||
await log.initZoned(transform, () async {
|
await log.initZoned(transform, () async {
|
||||||
@ -41,7 +34,6 @@ class TemplateCompiler extends Transformer implements DeclaringTransformer {
|
|||||||
var reader = new AssetReader.fromTransform(transform);
|
var reader = new AssetReader.fromTransform(transform);
|
||||||
var outputs = await processTemplates(reader, primaryId,
|
var outputs = await processTemplates(reader, primaryId,
|
||||||
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes);
|
reflectPropertiesAsAttributes: options.reflectPropertiesAsAttributes);
|
||||||
transform.consumePrimary();
|
|
||||||
var ngDepsCode = '';
|
var ngDepsCode = '';
|
||||||
var templatesCode = '';
|
var templatesCode = '';
|
||||||
if (outputs != null) {
|
if (outputs != null) {
|
||||||
|
@ -41,17 +41,6 @@ allTests() {
|
|||||||
.toBe(false);
|
.toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should declare outputs', () {
|
|
||||||
var transform = new FakeDeclaringTransform()
|
|
||||||
..primaryId = new AssetId('somepackage', 'lib/style.css');
|
|
||||||
subject.declareOutputs(transform);
|
|
||||||
expect(transform.outputs.length).toBe(2);
|
|
||||||
expect(transform.outputs[0].toString())
|
|
||||||
.toEqual('somepackage|lib/style.css.dart');
|
|
||||||
expect(transform.outputs[1].toString())
|
|
||||||
.toEqual('somepackage|lib/style.css.shim.dart');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should compile stylesheets', () async {
|
it('should compile stylesheets', () async {
|
||||||
var cssFile = new Asset.fromString(
|
var cssFile = new Asset.fromString(
|
||||||
new AssetId('somepackage', 'lib/style.css'), SIMPLE_CSS);
|
new AssetId('somepackage', 'lib/style.css'), SIMPLE_CSS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user