Skip to content

Commit

Permalink
[dart2wasm] Optimize RTT data structures
Browse files Browse the repository at this point in the history
This CL optimizes the RTT data structures by

* Having a canonical table for substitution arrays
* Stores the (canonical) substitution index to use right next
  to the super class id, thereby
* Removing an indirection when looking up substitutions

See more information in `sdk/lib/_internal/wasm/lib/type.dart`

This reduces
  * `Hello.Compile.Size.wasm.opt` by ~ 4%
  * `FluteComplex.Compile.Size.wasm.opt` by ~0.5%

Issue #55516

Change-Id: If0a50780a9a604886bd67a08a2f345103f0bcb32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369641
Reviewed-by: Ömer Ağacan <[email protected]>
Commit-Queue: Martin Kustermann <[email protected]>
  • Loading branch information
mkustermann authored and Commit Queue committed Jun 8, 2024
1 parent 6424397 commit 1e60700
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 212 deletions.
28 changes: 24 additions & 4 deletions pkg/dart2wasm/lib/intrinsics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'class_info.dart';
import 'code_generator.dart';
import 'dynamic_forwarders.dart';
import 'translator.dart';
import 'types.dart';

typedef CodeGenCallback = void Function(CodeGenerator);

Expand Down Expand Up @@ -112,6 +113,7 @@ class Intrinsifier {
};

Translator get translator => codeGen.translator;
Types get types => codeGen.translator.types;
w.InstructionsBuilder get b => codeGen.b;

DartType dartTypeOf(Expression exp) => codeGen.dartTypeOf(exp);
Expand Down Expand Up @@ -444,11 +446,29 @@ class Intrinsifier {
b.i32_const(0);
return w.NumType.i32;
case "_typeRulesSupers":
return translator.types.makeTypeRulesSupers(b);
case "_typeRulesSubstitutions":
return translator.types.makeTypeRulesSubstitutions(b);
final type = translator
.translateStorageType(types.rtt.typeRulesSupersType)
.unpacked;
translator.constants
.instantiateConstant(null, b, types.rtt.typeRulesSupers, type);
return type;
case "_canonicalSubstitutionTable":
final type = translator
.translateStorageType(types.rtt.substitutionTableConstantType)
.unpacked;
translator.constants.instantiateConstant(
null, b, types.rtt.substitutionTableConstant, type);
return type;
case "_typeNames":
return translator.types.makeTypeNames(b);
final type =
translator.translateStorageType(types.rtt.typeNamesType).unpacked;
if (translator.options.minify) {
b.ref_null((type as w.RefType).heapType);
} else {
translator.constants
.instantiateConstant(null, b, types.rtt.typeNames, type);
}
return type;
}
}

Expand Down
Loading

0 comments on commit 1e60700

Please sign in to comment.