Commit Graph

115 Commits

Author SHA1 Message Date
Takeshi Yoneda
0649820fb9 Removes non-static locals collection (#2236)
This stops gathering `NonStaticLocals` during validation phase,
which was previously used to do the "fast pass" on variable search
by the frontend. However, it had no impact after the last mile refactoring
included in 1.7.0 and caused tons of allocations.

As as result, you can see the compilation perf improvements especially
around memory pressure without any impacts on the runtime perf

### Zig 
```
goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero/internal/integration_test/stdlibs
                             │ old_zig.txt │           new_zig.txt            │
                             │   sec/op    │   sec/op    vs base              │
Zig/Compile/test-opt.wasm-10    3.769 ± 1%   3.761 ± 1%       ~ (p=0.485 n=6)
Zig/Run/test-opt.wasm-10        18.78 ± 1%   18.74 ± 0%  -0.21% (p=0.041 n=6)
Zig/Compile/test.wasm-10        4.677 ± 1%   4.515 ± 0%  -3.48% (p=0.002 n=6)
Zig/Run/test.wasm-10            19.31 ± 1%   19.27 ± 1%       ~ (p=1.000 n=6)
geomean                         8.942        8.850       -1.04%

                             │ old_zig.txt  │            new_zig.txt             │
                             │     B/op     │     B/op      vs base              │
Zig/Compile/test-opt.wasm-10   394.7Mi ± 0%   393.5Mi ± 0%  -0.30% (p=0.002 n=6)
Zig/Run/test-opt.wasm-10       741.7Mi ± 0%   741.7Mi ± 0%       ~ (p=0.621 n=6)
Zig/Compile/test.wasm-10       659.5Mi ± 0%   599.3Mi ± 0%  -9.12% (p=0.002 n=6)
Zig/Run/test.wasm-10           1.296Gi ± 0%   1.296Gi ± 0%       ~ (p=0.102 n=6)
geomean                        711.5Mi        694.2Mi       -2.44%

                             │ old_zig.txt │            new_zig.txt             │
                             │  allocs/op  │  allocs/op   vs base               │
Zig/Compile/test-opt.wasm-10   362.6k ± 0%   343.2k ± 0%   -5.34% (p=0.002 n=6)
Zig/Run/test-opt.wasm-10       51.58k ± 0%   51.58k ± 0%        ~ (p=0.978 n=6)
Zig/Compile/test.wasm-10       514.7k ± 0%   288.1k ± 0%  -44.04% (p=0.002 n=6)
Zig/Run/test.wasm-10           2.156M ± 0%   2.156M ± 0%        ~ (p=0.273 n=6)
geomean                        379.5k        323.8k       -14.69%
```

### TinyGo
```
goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero/internal/integration_test/stdlibs
                                      │ old_tinygo.txt │            new_tinygo.txt             │
                                      │     sec/op     │    sec/op      vs base                │
TinyGo/Compile/container_heap.test-10    410.8m ± 1%     399.8m ± 0%    -2.69% (p=0.001 n=7)
TinyGo/Run/container_heap.test-10        14.41m ± 0%     14.29m ± 2%    -0.77% (p=0.026 n=7)
TinyGo/Compile/container_list.test-10    410.5m ± 1%     398.1m ± 0%    -3.02% (p=0.001 n=7)
TinyGo/Run/container_list.test-10        14.27m ± 2%     14.16m ± 1%         ~ (p=0.073 n=7)
TinyGo/Compile/container_ring.test-10    403.7m ± 1%     392.5m ± 2%    -2.77% (p=0.001 n=7)
TinyGo/Run/container_ring.test-10        14.24m ± 0%     14.27m ± 1%         ~ (p=0.259 n=7)
TinyGo/Compile/crypto_des.test-10        418.8m ± 0%     408.1m ± 0%    -2.56% (p=0.001 n=7)
TinyGo/Run/crypto_des.test-10            18.23m ± 0%     18.17m ± 1%         ~ (p=0.456 n=7)
TinyGo/Compile/crypto_md5.test-10        417.3m ± 2%     406.1m ± 1%    -2.68% (p=0.001 n=7)
TinyGo/Run/crypto_md5.test-10            20.50m ± 0%     20.45m ± 1%         ~ (p=0.128 n=7)
TinyGo/Compile/crypto_rc4.test-10        402.2m ± 1%     390.5m ± 0%    -2.90% (p=0.001 n=7)
TinyGo/Run/crypto_rc4.test-10            160.8m ± 0%     161.0m ± 1%         ~ (p=1.000 n=7)
TinyGo/Compile/crypto_sha1.test-10       417.2m ± 1%     404.5m ± 1%    -3.04% (p=0.001 n=7)
TinyGo/Run/crypto_sha1.test-10           15.93m ± 1%     15.90m ± 1%         ~ (p=0.710 n=7)
TinyGo/Compile/crypto_sha256.test-10     423.4m ± 1%     412.4m ± 1%    -2.60% (p=0.001 n=7)
TinyGo/Run/crypto_sha256.test-10         16.16m ±  ∞ ¹   16.05m ±  ∞ ¹       ~ (p=0.381 n=2+5)
geomean                                  94.17m          92.70m         -1.56%
¹ need >= 6 samples for confidence interval at level 0.95

                                      │ old_tinygo.txt │             new_tinygo.txt             │
                                      │      B/op      │      B/op       vs base                │
TinyGo/Compile/container_heap.test-10   48.55Mi ± 0%     48.30Mi ± 0%    -0.52% (p=0.001 n=7)
TinyGo/Run/container_heap.test-10       16.63Mi ± 0%     16.63Mi ± 0%         ~ (p=0.557 n=7)
TinyGo/Compile/container_list.test-10   48.53Mi ± 0%     48.29Mi ± 0%    -0.51% (p=0.001 n=7)
TinyGo/Run/container_list.test-10       16.40Mi ± 0%     16.40Mi ± 0%         ~ (p=0.364 n=7)
TinyGo/Compile/container_ring.test-10   47.78Mi ± 0%     47.53Mi ± 0%    -0.52% (p=0.001 n=7)
TinyGo/Run/container_ring.test-10       16.30Mi ± 0%     16.30Mi ± 0%         ~ (p=0.128 n=7)
TinyGo/Compile/crypto_des.test-10       48.67Mi ± 0%     48.42Mi ± 0%    -0.51% (p=0.001 n=7)
TinyGo/Run/crypto_des.test-10           16.76Mi ± 0%     16.76Mi ± 0%         ~ (p=0.902 n=7)
TinyGo/Compile/crypto_md5.test-10       48.73Mi ± 0%     48.48Mi ± 0%    -0.51% (p=0.001 n=7)
TinyGo/Run/crypto_md5.test-10           44.97Mi ± 0%     44.97Mi ± 0%         ~ (p=0.402 n=7)
TinyGo/Compile/crypto_rc4.test-10       47.76Mi ± 0%     47.52Mi ± 0%    -0.51% (p=0.001 n=7)
TinyGo/Run/crypto_rc4.test-10           29.28Mi ± 0%     29.28Mi ± 0%         ~ (p=0.104 n=7)
TinyGo/Compile/crypto_sha1.test-10      48.97Mi ± 0%     48.72Mi ± 0%    -0.52% (p=0.001 n=7)
TinyGo/Run/crypto_sha1.test-10          17.44Mi ± 0%     17.44Mi ± 0%         ~ (p=1.000 n=7)
TinyGo/Compile/crypto_sha256.test-10    48.81Mi ± 0%     48.56Mi ± 0%    -0.51% (p=0.001 n=7)
TinyGo/Run/crypto_sha256.test-10        17.53Mi ±  ∞ ¹   17.53Mi ±  ∞ ¹       ~ (p=0.381 n=2+5)
geomean                                 31.45Mi          31.37Mi         -0.26%
¹ need >= 6 samples for confidence interval at level 0.95

                                      │ old_tinygo.txt │            new_tinygo.txt             │
                                      │   allocs/op    │   allocs/op    vs base                │
TinyGo/Compile/container_heap.test-10    83.67k ± 0%     83.46k ± 0%    -0.25% (p=0.011 n=7)
TinyGo/Run/container_heap.test-10        374.9k ± 0%     374.9k ± 0%         ~ (p=1.000 n=7)
TinyGo/Compile/container_list.test-10    83.34k ± 0%     83.19k ± 0%    -0.19% (p=0.002 n=7)
TinyGo/Run/container_list.test-10        370.0k ± 0%     370.0k ± 0%         ~ (p=0.674 n=7)
TinyGo/Compile/container_ring.test-10    83.26k ± 0%     83.08k ± 0%    -0.22% (p=0.004 n=7)
TinyGo/Run/container_ring.test-10        367.6k ± 0%     367.6k ± 0%         ~ (p=0.249 n=7)
TinyGo/Compile/crypto_des.test-10        83.68k ± 0%     83.53k ± 0%    -0.18% (p=0.004 n=7)
TinyGo/Run/crypto_des.test-10            378.1k ± 0%     378.1k ± 0%         ~ (p=0.437 n=7)
TinyGo/Compile/crypto_md5.test-10        83.86k ± 0%     83.67k ± 0%    -0.23% (p=0.001 n=7)
TinyGo/Run/crypto_md5.test-10            393.3k ± 0%     393.3k ± 0%         ~ (p=0.592 n=7)
TinyGo/Compile/crypto_rc4.test-10        83.32k ± 0%     83.20k ± 0%    -0.14% (p=0.011 n=7)
TinyGo/Run/crypto_rc4.test-10            367.1k ± 0%     367.1k ± 0%         ~ (p=0.102 n=7)
TinyGo/Compile/crypto_sha1.test-10       84.05k ± 0%     83.87k ± 0%    -0.21% (p=0.002 n=7)
TinyGo/Run/crypto_sha1.test-10           392.7k ± 0%     392.7k ± 0%         ~ (p=1.000 n=7)
TinyGo/Compile/crypto_sha256.test-10     83.86k ± 0%     83.67k ± 0%    -0.24% (p=0.001 n=7)
TinyGo/Run/crypto_sha256.test-10         394.5k ±  ∞ ¹   394.5k ±  ∞ ¹       ~ (p=0.952 n=2+5)
geomean                                  178.2k          178.0k         -0.10%
```

### wasip1

```
goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero/internal/integration_test/stdlibs
                                            │ old_wasip1.txt │           new_wasip1.txt            │
                                            │     sec/op     │   sec/op     vs base                │
Wasip1/Compile/src_archive_tar.test-10          2.066 ± 1%      2.066 ± 1%       ~ (p=1.000 n=7)
Wasip1/Run/src_archive_tar.test-10             398.9m ± 1%     398.9m ± 0%       ~ (p=0.902 n=7)
Wasip1/Compile/src_bufio.test-10                1.405 ± 0%      1.405 ± 0%       ~ (p=0.318 n=7)
Wasip1/Run/src_bufio.test-10                   120.1m ± 0%     120.0m ± 0%       ~ (p=0.456 n=7)
Wasip1/Compile/src_bytes.test-10                1.453 ± 0%      1.452 ± 0%       ~ (p=0.383 n=7)
Wasip1/Run/src_bytes.test-10                   468.9m ± 1%     467.7m ± 1%       ~ (p=1.000 n=7)
Wasip1/Compile/src_context.test-10              1.565 ± 0%      1.562 ± 0%  -0.18% (p=0.001 n=7)
Wasip1/Run/src_context.test-10                 31.52m ± 1%     31.51m ± 1%       ~ (p=0.620 n=7)
Wasip1/Compile/src_encoding_ascii85.test-10     1.262 ±  ∞ ¹    1.262 ± 0%       ~ (p=0.889 n=2+7)
geomean                                        565.3m          564.9m       -0.07%
¹ need >= 6 samples for confidence interval at level 0.95

                                            │ old_wasip1.txt │            new_wasip1.txt            │
                                            │      B/op      │     B/op      vs base                │
Wasip1/Compile/src_archive_tar.test-10        93.16Mi ± 0%     92.70Mi ± 0%  -0.50% (p=0.001 n=7)
Wasip1/Run/src_archive_tar.test-10            286.0Mi ± 0%     286.0Mi ± 0%       ~ (p=0.246 n=7)
Wasip1/Compile/src_bufio.test-10              74.12Mi ± 0%     73.79Mi ± 0%  -0.45% (p=0.001 n=7)
Wasip1/Run/src_bufio.test-10                  105.3Mi ± 0%     105.3Mi ± 0%       ~ (p=0.780 n=7)
Wasip1/Compile/src_bytes.test-10              75.32Mi ± 0%     74.96Mi ± 0%  -0.47% (p=0.001 n=7)
Wasip1/Run/src_bytes.test-10                  605.0Mi ± 0%     605.0Mi ± 0%       ~ (p=1.000 n=7)
Wasip1/Compile/src_context.test-10            78.07Mi ± 0%     77.68Mi ± 0%  -0.49% (p=0.001 n=7)
Wasip1/Run/src_context.test-10                71.52Mi ± 0%     71.52Mi ± 0%       ~ (p=0.516 n=7)
Wasip1/Compile/src_encoding_ascii85.test-10   70.38Mi ±  ∞ ¹   70.08Mi ± 0%       ~ (p=0.056 n=2+7)
geomean                                       115.7Mi          115.4Mi       -0.26%
¹ need >= 6 samples for confidence interval at level 0.95

                                            │ old_wasip1.txt │            new_wasip1.txt             │
                                            │   allocs/op    │  allocs/op   vs base                  │
Wasip1/Compile/src_archive_tar.test-10         265.0k ± 0%     256.1k ± 0%  -3.37% (p=0.001 n=7)
Wasip1/Run/src_archive_tar.test-10             7.831k ± 0%     7.830k ± 0%       ~ (p=0.592 n=7)
Wasip1/Compile/src_bufio.test-10               195.3k ± 0%     189.1k ± 0%  -3.19% (p=0.001 n=7)
Wasip1/Run/src_bufio.test-10                   3.728k ± 0%     3.728k ± 0%       ~ (p=1.000 n=7)   ¹
Wasip1/Compile/src_bytes.test-10               203.7k ± 0%     197.0k ± 0%  -3.31% (p=0.001 n=7)
Wasip1/Run/src_bytes.test-10                   6.377k ± 0%     6.377k ± 0%       ~ (p=0.559 n=7)
Wasip1/Compile/src_context.test-10             221.4k ± 0%     214.2k ± 0%  -3.29% (p=0.001 n=7)
Wasip1/Run/src_context.test-10                 3.814k ± 1%     3.814k ± 0%       ~ (p=0.192 n=7)
Wasip1/Compile/src_encoding_ascii85.test-10    182.3k ±  ∞ ²   176.6k ± 0%       ~ (p=0.056 n=2+7)
geomean                                        40.64k          39.90k       -1.82%
```

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-06-07 12:50:25 -07:00
Takeshi Yoneda
4dfb1f5b26 Propagates api.Memory.Grow by users to ModuleEngine (#2216)
Since the introduction of optimizing compiler, the Memory.Grow by the users,
which has the different call path than memory.grow instruction, didn't propagate
the growth result onto compiler's ModuleInstance.

Fixes #2215

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-05-27 10:37:03 +09:00
Nuno Cruces
a0fbb18544 experimental: configure custom memory allocator (#2177)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2024-04-10 20:13:57 +09:00
Takeshi Yoneda
cb0c399445 wazevo(frontend): fast pass for static local searches (#2116)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-05 10:02:34 +09:00
Anuraag Agrawal
5c70d8bbcc threads: add decoding of shared memory (#1914)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2024-01-11 19:32:08 -08:00
Takeshi Yoneda
27624049dc wazevo(frontend): faster non-imported global access (#1889)
Some checks failed
Release CLI / Pre-release build (push) Has been cancelled
Release CLI / Pre-release test (macos-12) (push) Has been cancelled
Release CLI / Pre-release test (ubuntu-22.04) (push) Has been cancelled
Release CLI / Pre-release test (windows-2022) (push) Has been cancelled
Release CLI / Release (push) Has been cancelled
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-12-22 08:04:48 -08:00
Takeshi Yoneda
a6ef3c7524 Changes ModuleID for listener existence per function (#1742)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-10-02 10:12:59 +09:00
Anuraag Agrawal
714368bcea Remove threads support (#1487)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-05-22 12:18:36 +10:00
Anuraag Agrawal
bc96257575 Implement WebAssembly threads proposal with interpreter (#1460)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2023-05-16 12:22:17 +08:00
Takeshi Yoneda
80452a94c3 Bulk lazy initialization of FunctionDefinitions (#1425)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Co-authored-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-05-12 08:02:40 +10:00
Takeshi Yoneda
d33ecd0e3a cache: fixes consistency with CloseOnContextDone and listeners (#1381)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-19 15:00:46 +09:00
Takeshi Yoneda
8ac9a54923 wasm: reduces allocs during import resolution (#1361)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-13 12:35:04 +09:00
Takeshi Yoneda
3cbd881201 binary: makes NameMap and IndirectNameMap slices over values, not ptrs (#1351)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-10 21:27:50 +09:00
Takeshi Yoneda
4f6b9f6637 Reuses bytes.Reader and value stack in func validation (#1340)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-04-04 10:31:15 +09:00
Takeshi Yoneda
ebe48da023 Reuses allocated slices in func validation (#1328)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-31 15:58:15 +09:00
Takeshi Yoneda
0857336746 Removes wasm.FunctionInstance type (#1294)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 14:43:44 +09:00
Takeshi Yoneda
9a87d2628b Removes validatedActiveElementSegment (#1292)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-28 08:19:40 +09:00
Takeshi Yoneda
a4226906cf Deletes wasm.CallCtx (#1280)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 17:00:43 -07:00
Takeshi Yoneda
d0fc0c6232 Import function type check at validation phrase (#1281)
Import function type check at compilation

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-24 09:10:18 +01:00
Takeshi Yoneda
cd1110c088 Avoids allocation of exports map per instance (#1275)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-23 16:37:56 +09:00
Takeshi Yoneda
cd05a22df2 Reduces allocations during instantiation (#1267)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:58 +09:00
Takeshi Yoneda
c20073d228 Removes unnecessary .Index field of FunctionInstance (#1270)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 18:55:35 +09:00
Takeshi Yoneda
f8eb6a8535 Removes unused function types on encoder/decoder (#1269)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-22 08:42:55 +01:00
Takeshi Yoneda
fe8784996c Avoides allocation with constExpr execution (#1257)
Previously executConstExpr is called various places, and therefore it was necessary to return interface{}
and that resulted in allocation per call.
This commit avoids the allocation by adding executConstExprI32 which is used by data segment manipulation,
and repurposes executConstExpr solely to global instance initialization.

As a result, this completely removes the allocation around const expr execution, and hence the perf improvement
in the instantiation phrase. The improvement diff is proportionate to the number of data segments and globals.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-20 12:56:25 +09:00
Takeshi Yoneda
8ab1615b53 Forbids empty name module imports (#1244)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-03-16 12:22:37 +09:00
Takeshi Yoneda
e17a85146a Holds wasm.Code as values on wasm.Module (#1243)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 14:45:54 +09:00
Takeshi Yoneda
350e81e632 Holds function types as values, not ptrs in wasm.Module (#1227)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:45:52 +09:00
Takeshi Yoneda
aba4ede088 Removes usage of host functions with Wasm optocdes (#1241)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-15 13:42:53 +09:00
Takeshi Yoneda
e42987a17a Holds memory/func defs, and validated elements as values in wasm.Module (#1224)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 14:52:01 +09:00
Takeshi Yoneda
7466f0e7bd Holds most fields as slice of values, not ptrs in wasm.Module (#1221)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-03-13 12:50:36 +09:00
Edoardo Vacchi
117474c477 refactor binary encoding to its own package (#1187)
move binary encoder to its own package

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-03 07:21:22 +08:00
Takeshi Yoneda
d57bdecadb gojs/test: resolve race under scheduleTimeoutEvent (#1063)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-26 08:26:34 +09:00
Takeshi Yoneda
b63d4e6dcd Deletes namespace API (#1018)
Formerly, we introduced `wazero.Namespace` to help avoid module name or import conflicts while still sharing the runtime's compilation cache. Now that we've introduced `CompilationCache` `wazero.Namespace` is no longer necessary. By removing it, we reduce the conceptual load on end users as well internal complexity. Since most users don't use namespace, the change isn't very impactful.

Users who are only trying to avoid module name conflict can generate a name like below instead of using multiple runtimes:

```go
moduleName := fmt.Sprintf("%d", atomic.AddUint64(&m.instanceCounter, 1))
module, err := runtime.InstantiateModule(ctx, compiled, config.WithName(moduleName))
```

For `HostModuleBuilder` users, we no longer take `Namespace` as the last parameter of `Instantiate` method: 

```diff
 	// log to the console.
 	_, err := r.NewHostModuleBuilder("env").
 		NewFunctionBuilder().WithFunc(logString).Export("log").
-		Instantiate(ctx, r)
+		Instantiate(ctx)
 	if err != nil {
 		log.Panicln(err)
 	}
```


The following is an example diff a use of namespace can use to keep compilation cache while also ensuring their modules don't conflict:

```diff

 func useMultipleRuntimes(ctx context.Context, cache) {
-	r := wazero.NewRuntime(ctx)
+	cache := wazero.NewCompilationCache()
 
 	for i := 0; i < N; i++ {
-		// Create a new namespace to instantiate modules into.
-		ns := r.NewNamespace(ctx) // Note: this is closed when the Runtime is
+		r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfig().WithCompilationCache(cache))
 
 		// Instantiate a new "env" module which exports a stateful function.
 		_, err := r.NewHostModuleBuilder("env").
```

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-10 14:11:46 +09:00
Takeshi Yoneda
e90e1985f3 Moves more func inst fields to comptime objects (#927)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2023-01-09 12:25:02 +09:00
Crypt Keeper
da3aa7a5ad Adds ExportedFunctionDefinitions and ExportedMemoryDefinitions (#986)
This adds ExportedFunctionDefinitions and ExportedMemoryDefinitions to
api.Module so that those who can't access CompileModule can see them.

Fixes #839

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-31 13:11:37 +08:00
Takeshi Yoneda
7666a2a7f7 Disable comp cache for host modules (#949)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-21 14:08:30 +09:00
Takeshi Yoneda
fafcb1cfee Removes unused FunctionInstance.LocalTypes (#925)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-15 14:40:09 +09:00
Takeshi Yoneda
fccbc7b2aa dwarf: fixes for unordered addresses of DWARF line entries (#905)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-09 09:12:33 +09:00
Takeshi Yoneda
4a60a8f4eb ModuleInstance.Functions/Exports as non-pointer slice (#894)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-07 12:45:06 +09:00
Anuraag Agrawal
5de9c3b4bc Store function objects in contiguous memory in heap (#892)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2022-12-06 17:07:16 +09:00
Takeshi Yoneda
b8adb361e8 Fixes FuncRef global initialization with imported globals (#888)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-06 14:32:12 +09:00
Crypt Keeper
af8105ba0e Adds ResultNames to HostFunctionBuilder and FunctionDefinition (#887)
This adds ResultNames to HostFunctionBuilder and FunctionDefinition
which helps for multi-results or special-cased ones.

End users can access result names in `FunctionDefinition.ResultNames` or
set for their own host functions via
`HostFunctionBuilder.WithResultNames`. This change adds them for all
built-in functions where result names help.

Most notably, GOOS=js uses `ProxyFunc` to allow logging when a function
returns multiple results. Before, the results were returned without
names: e.g. `11231,1` and now they are named like `n=11231,ok=1`.

We soon plan to allow more visibility in WASI, for example, logging
results that will write to memory offsets. This infrastructure makes it
possible to do that.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-12-06 14:30:55 +09:00
Takeshi Yoneda
6c4dd1cfd9 Adds support for DWARF based stack traces (#881)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-05 14:59:45 +09:00
Takeshi Yoneda
40e698e068 binary: adds custom section decoder (#877)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-12-01 20:08:40 +09:00
Takeshi Yoneda
8339045657 Ensures listeners only bound to compile time objects (#870)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-11-29 17:25:59 +09:00
Clifton Kaznocha
483dfe17c3 Replace module name check linear scan with map lookup (#844)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2022-11-07 22:38:29 +01:00
Clifton Kaznocha
0f19bb21ff Optimizes slice initializations (#842)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2022-11-07 08:25:37 +09:00
Clifton Kaznocha
f391a1d312 add ieee754 and leb128 byte slice funcs (#837)
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
2022-11-03 10:23:35 +08:00
Crypt Keeper
be33572289 Adds HostFunctionBuilder to enable high performance host functions (#828)
This PR follows @hafeidejiangyou advice to not only enable end users to
avoid reflection when calling host functions, but also use that approach
ourselves internally. The performance results are staggering and will be
noticable in high performance applications.

Before
```
BenchmarkHostCall/Call
BenchmarkHostCall/Call-16            	 1000000	      1050 ns/op
Benchmark_EnvironGet/environGet
Benchmark_EnvironGet/environGet-16         	  525492	      2224 ns/op
```

Now
```
BenchmarkHostCall/Call
BenchmarkHostCall/Call-16            	14807203	        83.22 ns/op
Benchmark_EnvironGet/environGet
Benchmark_EnvironGet/environGet-16         	  951690	      1054 ns/op
```

To accomplish this, this PR consolidates code around host function
definition and enables a fast path for functions where the user takes
responsibility for defining its WebAssembly mappings. Existing users
will need to change their code a bit, as signatures have changed.

For example, we are now more strict that all host functions require a
context parameter zero. Also, we've replaced
`HostModuleBuilder.ExportFunction` and `ExportFunctions` with a new type
`HostFunctionBuilder` that consolidates the responsibility and the
documentation.

```diff
 ctx := context.Background()
-hello := func() {
+hello := func(context.Context) {
         fmt.Fprintln(stdout, "hello!")
 }
-_, err := r.NewHostModuleBuilder("env").ExportFunction("hello", hello).Instantiate(ctx, r)
+_, err := r.NewHostModuleBuilder("env").
+        NewFunctionBuilder().WithFunc(hello).Export("hello").
+        Instantiate(ctx, r)
```

Power users can now use `HostFunctionBuilder` to define functions that
won't use reflection. There are two choices of interfaces to use
depending on if that function needs access to the calling module or not:
`api.GoFunction` and `api.GoModuleFunction`. Here's an example defining
one.

```go
builder.WithGoFunction(api.GoFunc(func(ctx context.Context, params []uint64) []uint64 {
	x, y := uint32(params[0]), uint32(params[1])
	sum := x + y
	return []uint64{sum}
}, []api.ValueType{api.ValueTypeI32, api.ValueTypeI32}, []api.ValueType{api.ValueTypeI32})
```
As you'll notice and as documented, this approach is more verbose and
not for everyone. If you aren't making a low-level library, you are
likely able to afford the 1us penalty for the convenience of reflection.
However, we are happy to enable this option for foundational libraries
and those with high performance requirements (like ourselves)!

Fixes #825

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-10-28 07:51:08 -07:00
Crypt Keeper
1cbb496c26 Stops using "ex." to abbreviate "for example" (#827)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2022-10-24 11:51:48 +09:00