Skip to content

Commit f02fd0c

Browse files
mkustermannCommit Queue
authored andcommitted
[dart2wasm] Change types builder to not use record types in maps
This reduces the time the codegen phase takes when compiling the essentials app by 33% (1 min 43 sec -> 1 min 8) Issue #61970 Change-Id: Ic26231a5823eeee24b562364e5cc6b03359792ba Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461822 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
1 parent b0dace7 commit f02fd0c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

pkg/wasm_builder/lib/src/builder/types.dart

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:collection';
6-
75
import 'package:collection/collection.dart';
86
import '../ir/ir.dart' as ir;
97
import 'builder.dart';
@@ -130,22 +128,16 @@ class _RecGroupBuilder {
130128
// (1) group length
131129
// (2) length of first struct
132130
// (3) group structural equality
133-
final equivalenceGroups =
134-
LinkedHashMap<(int, int, List<ir.DefType>), List<List<ir.DefType>>>(
135-
hashCode: (a) => Object.hash(a.$1, a.$2),
136-
equals: (a, b) =>
137-
a.$1 == b.$1 &&
138-
a.$2 == b.$2 &&
139-
_areGroupsStructurallyEqual(a.$3, b.$3),
140-
);
131+
final equivalenceGroups = <_RecursionGroupKey, List<List<ir.DefType>>>{};
141132

142133
for (final group in groups) {
143134
final structIndex = group.indexWhere((g) => g is ir.StructType);
144135
// Skip groups with no struct types.
145136
if (structIndex == -1) continue;
146137
final structType = group[structIndex] as ir.StructType;
147-
equivalenceGroups.putIfAbsent(
148-
(group.length, structType.fields.length, group), () => []).add(group);
138+
final key =
139+
_RecursionGroupKey(group.length, structType.fields.length, group);
140+
equivalenceGroups.putIfAbsent(key, () => []).add(group);
149141
}
150142

151143
for (final equalGroups in equivalenceGroups.values) {
@@ -351,3 +343,22 @@ class _FunctionTypeKey {
351343
return (inputHash * 2 + 1) * (outputHash * 2 + 1);
352344
}
353345
}
346+
347+
class _RecursionGroupKey {
348+
final int groupLength;
349+
final int lengthOfFirstStruct;
350+
final List<ir.DefType> types;
351+
352+
_RecursionGroupKey(this.groupLength, this.lengthOfFirstStruct, this.types);
353+
354+
@override
355+
int get hashCode => Object.hash(groupLength, lengthOfFirstStruct);
356+
357+
@override
358+
bool operator ==(other) {
359+
if (other is! _RecursionGroupKey) return false;
360+
if (groupLength != other.groupLength) return false;
361+
if (lengthOfFirstStruct != other.lengthOfFirstStruct) return false;
362+
return _RecGroupBuilder._areGroupsStructurallyEqual(types, other.types);
363+
}
364+
}

0 commit comments

Comments
 (0)