feat(dart/transform): Use the best available Change Detectors
Enable pregenerated (for Dart) and JIT (for Js) change detectors when possible. Previously we would always use `DynamicChangeDetector`s, but these cause megamorphic calls and are therefore much slower. Closes #502
This commit is contained in:
@ -88,20 +88,20 @@ class _DirectiveMetadataVisitor extends Object
|
||||
}
|
||||
|
||||
DirectiveMetadata get meta => DirectiveMetadata.create(
|
||||
type: _type,
|
||||
selector: _selector,
|
||||
compileChildren: _compileChildren,
|
||||
properties: _properties,
|
||||
host: _host,
|
||||
readAttributes: _readAttributes,
|
||||
exportAs: _exportAs,
|
||||
callOnDestroy: _callOnDestroy,
|
||||
callOnChange: _callOnChange,
|
||||
callOnCheck: _callOnCheck,
|
||||
callOnInit: _callOnInit,
|
||||
callOnAllChangesDone: _callOnAllChangesDone,
|
||||
changeDetection: _changeDetection,
|
||||
events: _events);
|
||||
type: _type,
|
||||
selector: _selector,
|
||||
compileChildren: _compileChildren,
|
||||
properties: _properties,
|
||||
host: _host,
|
||||
readAttributes: _readAttributes,
|
||||
exportAs: _exportAs,
|
||||
callOnDestroy: _callOnDestroy,
|
||||
callOnChange: _callOnChange,
|
||||
callOnCheck: _callOnCheck,
|
||||
callOnInit: _callOnInit,
|
||||
callOnAllChangesDone: _callOnAllChangesDone,
|
||||
changeDetection: _changeDetection,
|
||||
events: _events);
|
||||
|
||||
@override
|
||||
Object visitAnnotation(Annotation node) {
|
||||
|
@ -8,6 +8,9 @@ const DEFAULT_OPTIMIZATION_PHASES = 5;
|
||||
|
||||
const CUSTOM_ANNOTATIONS_PARAM = 'custom_annotations';
|
||||
const ENTRY_POINT_PARAM = 'entry_points';
|
||||
const GENERATE_CHANGE_DETECTORS_PARAM = 'generate_change_detectors';
|
||||
const INIT_REFLECTOR_PARAM = 'init_reflector';
|
||||
const MIRROR_MODE_PARAM = 'mirror_mode';
|
||||
const OPTIMIZATION_PHASES_PARAM = 'optimization_phases';
|
||||
const REFLECTION_ENTRY_POINT_PARAM = 'reflection_entry_points';
|
||||
|
||||
@ -32,6 +35,9 @@ class TransformerOptions {
|
||||
/// The [AnnotationMatcher] which is used to identify angular annotations.
|
||||
final AnnotationMatcher annotationMatcher;
|
||||
|
||||
/// Whether to create change detector classes for discovered `@View`s.
|
||||
final bool generateChangeDetectors;
|
||||
|
||||
/// The number of phases to spend optimizing output size.
|
||||
/// Each additional phase adds time to the transformation but may decrease
|
||||
/// final output size. There is a limit beyond which this will no longer
|
||||
@ -43,13 +49,15 @@ class TransformerOptions {
|
||||
|
||||
TransformerOptions._internal(this.entryPoints, this.reflectionEntryPoints,
|
||||
this.modeName, this.mirrorMode, this.initReflector,
|
||||
this.annotationMatcher, this.optimizationPhases);
|
||||
this.annotationMatcher, this.optimizationPhases,
|
||||
this.generateChangeDetectors);
|
||||
|
||||
factory TransformerOptions(List<String> entryPoints,
|
||||
{List<String> reflectionEntryPoints, String modeName: 'release',
|
||||
MirrorMode mirrorMode: MirrorMode.none, bool initReflector: true,
|
||||
List<AnnotationDescriptor> customAnnotationDescriptors: const [],
|
||||
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES}) {
|
||||
int optimizationPhases: DEFAULT_OPTIMIZATION_PHASES,
|
||||
bool generateChangeDetectors: true}) {
|
||||
if (reflectionEntryPoints == null || reflectionEntryPoints.isEmpty) {
|
||||
reflectionEntryPoints = entryPoints;
|
||||
}
|
||||
@ -58,6 +66,6 @@ class TransformerOptions {
|
||||
optimizationPhases = optimizationPhases.isNegative ? 0 : optimizationPhases;
|
||||
return new TransformerOptions._internal(entryPoints, reflectionEntryPoints,
|
||||
modeName, mirrorMode, initReflector, annotationMatcher,
|
||||
optimizationPhases);
|
||||
optimizationPhases, generateChangeDetectors);
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
||||
var entryPoints = _readFileList(config, ENTRY_POINT_PARAM);
|
||||
var reflectionEntryPoints =
|
||||
_readFileList(config, REFLECTION_ENTRY_POINT_PARAM);
|
||||
var initReflector = !config.containsKey('init_reflector') ||
|
||||
config['init_reflector'] != false;
|
||||
var initReflector =
|
||||
_readBool(config, INIT_REFLECTOR_PARAM, defaultValue: true);
|
||||
var generateChangeDetectors =
|
||||
_readBool(config, GENERATE_CHANGE_DETECTORS_PARAM, defaultValue: true);
|
||||
String mirrorModeVal =
|
||||
config.containsKey('mirror_mode') ? config['mirror_mode'] : '';
|
||||
config.containsKey(MIRROR_MODE_PARAM) ? config[MIRROR_MODE_PARAM] : '';
|
||||
var mirrorMode = MirrorMode.none;
|
||||
switch (mirrorModeVal) {
|
||||
case 'debug':
|
||||
@ -34,7 +36,14 @@ TransformerOptions parseBarbackSettings(BarbackSettings settings) {
|
||||
mirrorMode: mirrorMode,
|
||||
initReflector: initReflector,
|
||||
customAnnotationDescriptors: _readCustomAnnotations(config),
|
||||
optimizationPhases: optimizationPhases);
|
||||
optimizationPhases: optimizationPhases,
|
||||
generateChangeDetectors: generateChangeDetectors);
|
||||
}
|
||||
|
||||
bool _readBool(Map config, String paramName, {bool defaultValue}) {
|
||||
return config.containsKey(paramName)
|
||||
? config[paramName] != false
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
/// Cribbed from the polymer project.
|
||||
|
Reference in New Issue
Block a user