You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During coding, there are always lots of never changed static data which is similar as .text section in ELF.
2
+
3
+
In AS, this type of immutable data mainly includes string literals and function object.
4
+
5
+
## Function Object
6
+
7
+
For function objects, if we can identify this kinds of data, we can simplify lots of indirect function call.
8
+
9
+
Considering below example for function object:
10
+
11
+
```ts
12
+
function v(fn: () =>void):void {
13
+
fn();
14
+
}
15
+
v(() => {});
16
+
```
17
+
18
+
Arrow function `() => {}` will be compiled as function object which stored in static data area with function index `I`.
19
+
The function `v` will accept a `ptr` which is pointing to the function object. During calling `fn`, the function index will be load from `ptr` and call arrow function by `call_indirect`.
20
+
21
+
After eliminate the load data from immutable data area, subsequence compilation optimization can infer the function index in `call_indirect` is never changed and simplify it as `call`.
22
+
23
+
## String Literal
24
+
25
+
not implement yet.
26
+
27
+
## How
28
+
29
+
Binaryen cannot optimize this cases directly because this semantics cannot be properly expressed in a wasm spec.
30
+
31
+
The pass rely on the additional information `ImmutableDataElementRanges` passed in `AsModule` which define the ranges of immutable data.
32
+
33
+
When load data inside this range, the load instruction will be replaced as const instruction.
0 commit comments