Commit 302885c
[dart2wasm] Smaller
Currently we are quite agressive when inlining `as T` type checks. This
is due to a number of `@pragma('wasm:prefer-inline')` annotations
combined with `@pragma('wasm:static-dispatch')` annotations causing us
to generate polymorphic dispatcher functions for calls to
`_Type._checkInstance`, combined with the polymorphic call target force
inlining targets with <= 2 specializations.
These combination of factors lead to a `x as T` to become something like
<... code for checking x & T's nullability ...>
classId = x.classId;
if classId = ClassId.getClassId(_InterfaceClass)
...
else
...
This lead to binaryen sometimes infer the `x.classId` value to be a
constant which prunes the branches which then calls the faster path for
interface type checks.
Though this is quite a lot of code size. So instead of inlining all
these things, but still taking advantage of the binaryen global
optimizations that may infer `x.classId` we load the class id (which
binaryen may sometimes turn into a constant) and then pass it to the
polymorphic dispatcher (which we no longer inline to safe code size).
This way if the class id is a constant, either binaryen or V8 will see
that it can inline the polymorphic dispatcher as most of its body
disappears if the class id is known.
Since we no longer inline the polyhmorphic dispatcher, we can now also
mark other common types via `@pragma('wasm:static-dispatch')` - such as
`_RecordType._checkInstance`. This in return will speed up any code that
uses records in collections (e.g. in maps / sets / lists) as the
covariance checks now involve loading class id and branching on it to a
devirtualized `_RecordType._checkInstance` instead of an indirect call
that also involves a function type check).
We also remove the `@pragma('wasm:prefer-inline')` on the
`_checkSubclassRelationshipViaTable` function: The idea was that if
binaryen infers the load of class id most of the code that follows can
be optimized away at compile time. Unfortunately the tables can get
large, which made us not use `ImmutableWasmArray` but instead normal
`WasmArray`. That in return makes binaryen unable to optimize loads from
it (at constant index) away, as the contents of the array may change
(they never do, but binaryen doesn't know that). So there's little
benefit in inlining it.
Change-Id: I416fbdd35c6425a626378f2e9ea2009e50bf600b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420320
Reviewed-by: Ömer Ağacan <[email protected]>
Commit-Queue: Martin Kustermann <[email protected]>as T type checks due to less inlining1 parent 727c0e5 commit 302885c
File tree
3 files changed
+19
-9
lines changed- pkg/dart2wasm/lib
- sdk/lib/_internal/wasm/lib
3 files changed
+19
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1976 | 1976 | | |
1977 | 1977 | | |
1978 | 1978 | | |
| 1979 | + | |
| 1980 | + | |
1979 | 1981 | | |
1980 | 1982 | | |
1981 | 1983 | | |
1982 | 1984 | | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
1983 | 1989 | | |
1984 | 1990 | | |
1985 | | - | |
| 1991 | + | |
1986 | 1992 | | |
1987 | 1993 | | |
1988 | 1994 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2373 | 2373 | | |
2374 | 2374 | | |
2375 | 2375 | | |
2376 | | - | |
| 2376 | + | |
2377 | 2377 | | |
2378 | 2378 | | |
2379 | 2379 | | |
| |||
2382 | 2382 | | |
2383 | 2383 | | |
2384 | 2384 | | |
2385 | | - | |
2386 | | - | |
| 2385 | + | |
| 2386 | + | |
2387 | 2387 | | |
2388 | 2388 | | |
2389 | 2389 | | |
| |||
2413 | 2413 | | |
2414 | 2414 | | |
2415 | 2415 | | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
2416 | 2419 | | |
2417 | 2420 | | |
2418 | | - | |
| 2421 | + | |
2419 | 2422 | | |
2420 | 2423 | | |
2421 | 2424 | | |
2422 | 2425 | | |
2423 | 2426 | | |
2424 | 2427 | | |
2425 | | - | |
| 2428 | + | |
2426 | 2429 | | |
2427 | | - | |
| 2430 | + | |
2428 | 2431 | | |
2429 | 2432 | | |
2430 | 2433 | | |
2431 | 2434 | | |
2432 | 2435 | | |
2433 | | - | |
2434 | 2436 | | |
2435 | 2437 | | |
2436 | 2438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
450 | 451 | | |
451 | 452 | | |
452 | 453 | | |
| 454 | + | |
453 | 455 | | |
454 | 456 | | |
455 | 457 | | |
| |||
581 | 583 | | |
582 | 584 | | |
583 | 585 | | |
| 586 | + | |
584 | 587 | | |
585 | 588 | | |
586 | 589 | | |
| |||
1210 | 1213 | | |
1211 | 1214 | | |
1212 | 1215 | | |
1213 | | - | |
1214 | 1216 | | |
1215 | 1217 | | |
1216 | 1218 | | |
| |||
0 commit comments