Repository navigation
Commit db8a594
[query] Dispatch TypeCheck on a per-node tag
TypeCheck.checkSingleNode was one match of about 20.8 KB of bytecode.
HotSpot never compiles a method over 8000 bytes, since
DontCompileHugeMethods is on by default. So it always ran in the
interpreter.
Every IR node class now carries a tag, and TypeCheck switches on it in
two levels. checkSingleNode switches on the node's family and calls one
method per family, which switches on the tag. Both levels compile to
jump tables. Each case casts the node and reads its fields. The largest
method, checkStream, is 4.2 KB.
ir-gen puts each node in one family, named where the node is defined:
node(Const, "I32", ...). There are 13 families: Const, Core, Struct,
Stream, Collection, Agg, IO, NDArray, Random, Relational, Table, Matrix
and BlockMatrix. Relational, Table and Matrix hold the nodes a lowering
pass removes, and a node goes in the family of the first invariant that
forbids it. BlockMatrix is removed at the same point as Table, and takes
the nodes that read or make a block matrix but no Table. The other
families are buckets that keep each method small, and a node goes in
the family of what it produces.
A tag holds the family in the bits above Tag.FamilyShift and the node's
position in its family below. Within a family, nodes are ordered so the
cases TypeCheck and ChildEnv handle sit on consecutive tags, which keeps
each switch dense enough to compile to a jump table.
ir-gen writes Tag_gen.scala, with the Family and Tag value classes and
an Int constant for each family and node. The constants are untyped
final vals, so a @switch on them compiles to a jump table. The Table,
Matrix and BlockMatrix nodes are written by hand. ir-gen lists them
among the generated nodes as handWritten(Table, "TableRead") and
generates their tags too.
BaseIR takes the tag as a final constructor field, so reading it is a
field load. An overridden def tag was a virtual call HotSpot could not
inline, and made TypeCheck 11% slower on a 1000-field MakeStruct. Tag
stores a Short, which fits in padding most node classes already have.
203 of 217 classes keep their size. Weighted by node visits in the
Python test suite, the average node grows from 42.4 to 42.5 bytes.
The NDArrayIR trait goes. ir-gen marks those nodes TypedIR[TNDArray]
instead, and TypeCheck reads x.typ.elementType.
In IRPassBenchmark, against the previous commit, TypeCheck drops from
4.9 ms to 1.0 ms on a 3000-binding Block, from 5.3 ms to 0.58 ms on
2000 nested StreamMaps, from 6.6 ms to 0.92 ms on a balanced tree and
from 1.5 ms to 0.26 ms on a 1000-field MakeStruct. The gain comes from
getting each method under 8000 bytes. A version that only split the
instanceof chain into four methods ran within noise of the tag version
over 3 forks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 6955c2d commit db8a594
10 files changed
Lines changed: 1566 additions & 997 deletions
File tree
- hail/hail
- ir-gen/src
- src/is/hail/expr/ir
- lowering
- invariant
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
261 | 262 | | |
262 | 263 | | |
263 | 264 | | |
264 | | - | |
| 265 | + | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| |||
398 | 399 | | |
399 | 400 | | |
400 | 401 | | |
401 | | - | |
| 402 | + | |
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| |||
529 | 530 | | |
530 | 531 | | |
531 | 532 | | |
532 | | - | |
| 533 | + | |
533 | 534 | | |
534 | 535 | | |
535 | 536 | | |
| |||
588 | 589 | | |
589 | 590 | | |
590 | 591 | | |
591 | | - | |
| 592 | + | |
592 | 593 | | |
593 | 594 | | |
594 | 595 | | |
| |||
679 | 680 | | |
680 | 681 | | |
681 | 682 | | |
682 | | - | |
| 683 | + | |
683 | 684 | | |
684 | 685 | | |
685 | 686 | | |
| |||
729 | 730 | | |
730 | 731 | | |
731 | 732 | | |
732 | | - | |
| 733 | + | |
733 | 734 | | |
734 | 735 | | |
735 | 736 | | |
| |||
772 | 773 | | |
773 | 774 | | |
774 | 775 | | |
775 | | - | |
| 776 | + | |
| 777 | + | |
776 | 778 | | |
777 | 779 | | |
778 | 780 | | |
| |||
897 | 899 | | |
898 | 900 | | |
899 | 901 | | |
900 | | - | |
| 902 | + | |
901 | 903 | | |
902 | 904 | | |
903 | 905 | | |
| |||
915 | 917 | | |
916 | 918 | | |
917 | 919 | | |
918 | | - | |
| 920 | + | |
919 | 921 | | |
920 | 922 | | |
921 | 923 | | |
| |||
986 | 988 | | |
987 | 989 | | |
988 | 990 | | |
989 | | - | |
| 991 | + | |
990 | 992 | | |
991 | 993 | | |
992 | 994 | | |
| |||
1041 | 1043 | | |
1042 | 1044 | | |
1043 | 1045 | | |
1044 | | - | |
| 1046 | + | |
1045 | 1047 | | |
1046 | 1048 | | |
1047 | 1049 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
| 136 | + | |
| 137 | + | |
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | 351 | | |
356 | 352 | | |
357 | 353 | | |
| |||
0 commit comments