Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1133)

Unified Diff: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart

Issue 256453004: Avoid inlining constants that are used via a deferred import. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
index 5daff8ea43850a0985a93c89ff3bbd3bf2c8dd4f..0060900d8ce03ddd7b2f2ef3819df4f84ea2e342 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart
@@ -33,6 +33,8 @@ class CodeEmitterTask extends CompilerTask {
final Set<ClassElement> neededClasses = new Set<ClassElement>();
final Map<OutputUnit, List<ClassElement>> outputClassLists =
new Map<OutputUnit, List<ClassElement>>();
+ final Map<OutputUnit, List<Constant>> outputConstantLists =
+ new Map<OutputUnit, List<Constant>>();
final List<ClassElement> nativeClasses = <ClassElement>[];
final Map<String, String> mangledFieldNames = <String, String>{};
final Map<String, String> mangledGlobalFieldNames = <String, String>{};
@@ -890,26 +892,9 @@ class CodeEmitterTask extends CompilerTask {
}
void emitCompileTimeConstants(CodeBuffer buffer, OutputUnit outputUnit) {
- JavaScriptConstantCompiler handler = backend.constants;
- List<Constant> constants = handler.getConstantsForEmission(
- compareConstants);
- Set<Constant> outputUnitConstants = null;
- // TODO(sigurdm): We shouldn't run through all constants for every
- // outputUnit.
+ List<Constant> constants = outputConstantLists[outputUnit];
+ if (constants == null) return;
for (Constant constant in constants) {
- if (isConstantInlinedOrAlreadyEmitted(constant)) continue;
- OutputUnit constantUnit =
- compiler.deferredLoadTask.outputUnitForConstant(constant);
- if (constantUnit != outputUnit && constantUnit != null) continue;
- if (outputUnit != compiler.deferredLoadTask.mainOutputUnit
- && constantUnit == null) {
- // The back-end introduces some constants, like "InterceptorConstant" or
- // some list constants. They are emitted in the main output-unit, and
- // ignored otherwise.
- // TODO(sigurdm): We should track those constants.
- continue;
- }
-
String name = namer.constantName(constant);
if (constant.isList) emitMakeConstantListIfNotEmitted(buffer);
jsAst.Expression init = js('#.# = #',
@@ -1094,6 +1079,28 @@ class CodeEmitterTask extends CompilerTask {
}
/**
+ * Compute all the constants that must be emitted.
+ */
+ void computeNeededConstants() {
+ JavaScriptConstantCompiler handler = backend.constants;
+ List<Constant> constants = handler.getConstantsForEmission(
+ compareConstants);
+ for (Constant constant in constants) {
+ if (isConstantInlinedOrAlreadyEmitted(constant)) continue;
+ OutputUnit constantUnit =
+ compiler.deferredLoadTask.outputUnitForConstant(constant);
+ if (constantUnit == null) {
+ // The back-end introduces some constants, like "InterceptorConstant" or
+ // some list constants. They are emitted in the main output-unit.
+ // TODO(sigurdm): We should track those constants.
+ constantUnit = compiler.deferredLoadTask.mainOutputUnit;
+ }
+ outputConstantLists.putIfAbsent(constantUnit, () => new List<Constant>())
+ .add(constant);
+ }
+ }
+
+ /**
* Compute all the classes that must be emitted.
*/
void computeNeededClasses() {
@@ -1464,6 +1471,7 @@ class CodeEmitterTask extends CompilerTask {
// which may need getInterceptor (and one-shot interceptor) methods, so
// we have to make sure that [emitGetInterceptorMethods] and
// [emitOneShotInterceptors] have been called.
+ computeNeededConstants();
emitCompileTimeConstants(mainBuffer, mainOutputUnit);
// Write a javascript mapping from Deferred import load ids (derrived from

Powered by Google App Engine
This is Rietveld 408576698