Commit 9687f72
authored
[wasm-split] Split globals' transitive global dependencies (#8442)
When a global is exclusively used by a secondary module, we can move it
to the secondary module. If its initializer contains a `global.get` of
another global, we exported it from the primary module to the secondary
module, even if it may not be used anywhere else.
When we split a global out to a secondary module, this PR computes the
transitive dependency of the split global, and if those globals in the
dependency are not used anywhere else in other modules, we move them to
the secondary module as well.
#8441 and this PR combined reduce the size of the primary module of
acx_gallery by 42.6%.
The running time of `wasm-split` hasn't really changed with this PR,
compared to #8441.
---
`wasm-objdump -h` result:
- Before (#8441)
```
Type start=0x0000000c end=0x00035d44 (size=0x00035d38) count: 11185
Import start=0x00035d49 end=0x003faf6f (size=0x003c5226) count: 56805
Function start=0x003faf73 end=0x0040de1f (size=0x00012eac) count: 62890
Table start=0x0040de22 end=0x0041195d (size=0x00003b3b) count: 2921
Tag start=0x0041195f end=0x00411963 (size=0x00000004) count: 1
Global start=0x00411967 end=0x005541c5 (size=0x0014285e) count: 47771
Export start=0x005541c9 end=0x005dfc2c (size=0x0008ba63) count: 59077
Start start=0x005dfc2e end=0x005dfc30 (size=0x00000002) start: 828
Elem start=0x005dfc34 end=0x00649a77 (size=0x00069e43) count: 12303
DataCount start=0x00649a79 end=0x00649a7a (size=0x00000001) count: 1
Code start=0x00649a7f end=0x00879385 (size=0x0022f906) count: 62890
Data start=0x00879389 end=0x00898f16 (size=0x0001fb8d) count: 1
```
- After (This PR)
```
Type start=0x0000000c end=0x00035d44 (size=0x00035d38) count: 11185
Import start=0x00035d48 end=0x00132efc (size=0x000fd1b4) count: 32642
Function start=0x00132f00 end=0x00145dac (size=0x00012eac) count: 62890
Table start=0x00145daf end=0x001498ea (size=0x00003b3b) count: 2921
Tag start=0x001498ec end=0x001498f0 (size=0x00000004) count: 1
Global start=0x001498f4 end=0x00289e60 (size=0x0014056c) count: 47728
Export start=0x00289e64 end=0x002e99c1 (size=0x0005fb5d) count: 35861
Start start=0x002e99c3 end=0x002e99c5 (size=0x00000002) start: 828
Elem start=0x002e99c9 end=0x0035380c (size=0x00069e43) count: 12303
DataCount start=0x0035380e end=0x0035380f (size=0x00000001) count: 1
Code start=0x00353814 end=0x005830e5 (size=0x0022f8d1) count: 62890
Data start=0x005830e9 end=0x005a2c76 (size=0x0001fb8d) count: 1
```
Note that while the decrease in the global section is small, we have a
significant size decrease in the import and the export sections, because
we used to import globals and export them just to relay those globals to
the secondary modules.
Follow-up: #8443
Fixes #7724.1 parent c7a6976 commit 9687f72
2 files changed
Lines changed: 97 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
583 | 584 | | |
584 | 585 | | |
585 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
586 | 606 | | |
587 | 607 | | |
588 | 608 | | |
| |||
977 | 997 | | |
978 | 998 | | |
979 | 999 | | |
980 | | - | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
981 | 1013 | | |
982 | 1014 | | |
983 | 1015 | | |
| |||
1009 | 1041 | | |
1010 | 1042 | | |
1011 | 1043 | | |
1012 | | - | |
1013 | 1044 | | |
1014 | 1045 | | |
1015 | 1046 | | |
| |||
1019 | 1050 | | |
1020 | 1051 | | |
1021 | 1052 | | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1026 | 1058 | | |
1027 | | - | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
1028 | 1063 | | |
1029 | 1064 | | |
1030 | 1065 | | |
1031 | 1066 | | |
1032 | 1067 | | |
1033 | | - | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
1034 | 1072 | | |
1035 | 1073 | | |
1036 | 1074 | | |
1037 | 1075 | | |
1038 | 1076 | | |
| 1077 | + | |
1039 | 1078 | | |
1040 | | - | |
| 1079 | + | |
1041 | 1080 | | |
1042 | 1081 | | |
1043 | 1082 | | |
| |||
1127 | 1166 | | |
1128 | 1167 | | |
1129 | 1168 | | |
| 1169 | + | |
1130 | 1170 | | |
1131 | 1171 | | |
1132 | 1172 | | |
1133 | 1173 | | |
1134 | 1174 | | |
1135 | 1175 | | |
1136 | | - | |
| 1176 | + | |
1137 | 1177 | | |
1138 | 1178 | | |
1139 | 1179 | | |
1140 | 1180 | | |
1141 | 1181 | | |
1142 | 1182 | | |
1143 | | - | |
| 1183 | + | |
1144 | 1184 | | |
1145 | 1185 | | |
1146 | 1186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | | - | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | | - | |
18 | | - | |
| 22 | + | |
| 23 | + | |
19 | 24 | | |
20 | | - | |
21 | | - | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
26 | 33 | | |
27 | | - | |
28 | 34 | | |
29 | | - | |
30 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
31 | 41 | | |
32 | | - | |
33 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
34 | 46 | | |
35 | 47 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
39 | 56 | | |
40 | | - | |
41 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
42 | 64 | | |
43 | 65 | | |
0 commit comments