wazero icon indicating copy to clipboard operation
wazero copied to clipboard

ssa: empirically faster passRedundantPhiEliminationOpt

Open mathetake opened this issue 1 year ago • 1 comments

This changes the order of traversal of basic blocks in passRedundantPhiEliminationOpt optimization pass in a way that the algorithm converges more quickly. In order to do so, run the pass after the control flow analysis and traverse the blocks in the reverse post order.

This improves the compilation performance like 10-30% especially for Go and TinyGo binaries without having any influence on the runtime performance (exactly the same executables as before).

Stdlibs

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         3.114 ±  2%      2.335 ±  7%    -25.02% (p=0.001 n=7)
Wasip1/Run/src_archive_tar.test-10            399.7m ±  3%     399.9m ±  2%          ~ (p=0.456 n=7)
Wasip1/Compile/src_bufio.test-10               1.874 ±  1%      1.574 ±  1%    -16.00% (p=0.001 n=7)
Wasip1/Run/src_bufio.test-10                  122.9m ± 13%     125.6m ±  4%          ~ (p=0.620 n=7)
Wasip1/Compile/src_bytes.test-10               1.987 ±  1%      1.639 ±  1%    -17.50% (p=0.001 n=7)
Wasip1/Run/src_bytes.test-10                  471.4m ±  0%     470.4m ±  0%          ~ (p=0.456 n=7)
Wasip1/Compile/src_context.test-10             2.086 ±  1%      1.752 ±  3%    -16.02% (p=0.001 n=7)
Wasip1/Run/src_context.test-10                31.78m ±  9%     30.91m ±  2%     -2.74% (p=0.038 n=7)
Wasip1/Compile/src_encoding_ascii85.test-10    1.727 ±  3%      1.407 ±  1%    -18.54% (p=0.001 n=7)
Wasip1/Run/src_encoding_ascii85.test-10       7.536m ±  3%     7.530m ±  1%          ~ (p=1.000 n=7)
Wasip1/Compile/src_encoding_asn1.test-10       1.948 ±  1%      1.637 ±  1%    -15.99% (p=0.001 n=7)
Wasip1/Run/src_encoding_asn1.test-10          8.542m ±  6%     8.425m ±  2%          ~ (p=0.128 n=7)
Wasip1/Compile/src_encoding_base32.test-10     1.790 ±  1%      1.462 ±  1%    -18.32% (p=0.001 n=7)
Wasip1/Run/src_encoding_base32.test-10        28.82m ±  3%     27.81m ±  1%     -3.53% (p=0.002 n=7)
Wasip1/Compile/src_encoding_base64.test-10     1.817 ±  1%      1.472 ±  0%    -19.00% (p=0.001 n=7)
Wasip1/Run/src_encoding_base64.test-10        12.31m ±  2%     12.17m ±  2%          ~ (p=0.209 n=7)
Wasip1/Compile/src_encoding_binary.test-10     1.843 ±  2%      1.651 ± 14%    -10.38% (p=0.026 n=7)
Wasip1/Run/src_encoding_binary.test-10        9.444m ±  4%     9.583m ±  4%     +1.46% (p=0.038 n=7)
Wasip1/Compile/src_encoding_csv.test-10        1.789 ±  1%      1.500 ±  1%    -16.17% (p=0.001 n=7)
Wasip1/Run/src_encoding_csv.test-10           19.99m ±   ∞ ¹   20.85m ±  4%          ~ (p=0.250 n=1+7)
Wasip1/Compile/src_encoding_gob.test-10                         2.165 ±  1%
geomean                                       264.3m           314.9m           -9.16%

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     668.8m ±  2%     445.6m ±  9%  -33.38% (p=0.001 n=7)
TinyGo/Run/container_heap.test-10         14.42m ± 11%     14.53m ±  7%        ~ (p=0.318 n=7)
TinyGo/Compile/container_list.test-10     663.8m ±  1%     433.9m ±  2%  -34.64% (p=0.001 n=7)
TinyGo/Run/container_list.test-10         14.26m ± 10%     14.17m ±  7%        ~ (p=0.318 n=7)
TinyGo/Compile/container_ring.test-10     665.9m ±  1%     435.6m ±  4%  -34.58% (p=0.001 n=7)
TinyGo/Run/container_ring.test-10         14.24m ± 12%     14.49m ±  2%        ~ (p=0.259 n=7)
TinyGo/Compile/crypto_des.test-10         692.5m ±  4%     452.5m ±  9%  -34.66% (p=0.001 n=7)
TinyGo/Run/crypto_des.test-10             18.32m ±  4%     18.14m ±  3%        ~ (p=0.128 n=7)
TinyGo/Compile/crypto_md5.test-10         681.3m ±  3%     450.5m ±  4%  -33.88% (p=0.001 n=7)
TinyGo/Run/crypto_md5.test-10             20.90m ±  4%     20.80m ±  8%        ~ (p=1.000 n=7)
TinyGo/Compile/crypto_rc4.test-10         673.2m ±  4%     429.0m ±  3%  -36.28% (p=0.001 n=7)
TinyGo/Run/crypto_rc4.test-10             162.7m ±  1%     162.7m ±  1%        ~ (p=0.902 n=7)
TinyGo/Compile/crypto_sha1.test-10        679.4m ±  3%     437.5m ±  3%  -35.61% (p=0.001 n=7)
TinyGo/Run/crypto_sha1.test-10            16.02m ±  6%     16.33m ±  3%        ~ (p=0.535 n=7)
TinyGo/Compile/crypto_sha256.test-10      697.0m ±  4%     445.0m ±  0%  -36.15% (p=0.001 n=7)
TinyGo/Run/crypto_sha256.test-10          16.10m ±  7%     15.91m ±  1%   -1.13% (p=0.017 n=7)
TinyGo/Compile/crypto_sha512.test-10      698.2m ±  3%     450.0m ±  2%  -35.56% (p=0.001 n=7)
TinyGo/Run/crypto_sha512.test-10          20.26m ±  7%     18.76m ±  1%   -7.41% (p=0.017 n=7)
TinyGo/Compile/encoding_ascii85.test-10   681.4m ±  4%     435.9m ±  1%  -36.03% (p=0.001 n=7)
TinyGo/Run/encoding_ascii85.test-10       14.88m ±  1%     14.93m ± 12%        ~ (p=0.318 n=7)
TinyGo/Compile/encoding_base32.test-10     1.645 ±  4%      1.165 ±  4%  -29.19% (p=0.001 n=7)
TinyGo/Run/encoding_base32.test-10        86.46m ±  4%     88.18m ±  5%        ~ (p=0.209 n=7)
TinyGo/Compile/encoding_csv.test-10       734.2m ±  1%     483.1m ±  5%  -34.20% (p=0.001 n=7)
TinyGo/Run/encoding_csv.test-10           22.85m ±  6%     22.86m ±  0%        ~ (p=1.000 n=7)
TinyGo/Compile/encoding_hex.test-10       699.8m ±  5%     455.9m ±  2%  -34.86% (p=0.001 n=7)
TinyGo/Run/encoding_hex.test-10           10.23m ±  4%     10.23m ±  5%        ~ (p=0.805 n=7)
TinyGo/Compile/go_scanner.test-10         752.3m ±  3%     485.0m ±  1%  -35.53% (p=0.001 n=7)
TinyGo/Run/go_scanner.test-10             16.70m ±  5%     16.62m ±  8%        ~ (p=0.620 n=7)
TinyGo/Compile/hash.test-10               948.3m ±  2%     690.5m ±  1%  -27.19% (p=0.001 n=7)
TinyGo/Run/hash.test-10                   16.19m ±  5%     16.14m ±  5%        ~ (p=0.902 n=7)
TinyGo/Compile/hash_adler32.test-10       663.8m ±  3%     423.4m ±  3%  -36.22% (p=0.001 n=7)
TinyGo/Run/hash_adler32.test-10           24.75m ±  8%     24.62m ±  1%        ~ (p=0.535 n=7)
TinyGo/Compile/hash_crc64.test-10         887.8m ±  3%     653.2m ±  1%  -26.43% (p=0.001 n=7)
TinyGo/Run/hash_crc64.test-10             17.27m ±  1%     17.53m ±  5%   +1.48% (p=0.017 n=7)
TinyGo/Compile/hash_fnv.test-10           685.6m ±  7%     443.7m ±  4%  -35.28% (p=0.001 n=7)
TinyGo/Run/hash_fnv.test-10               15.49m ±  4%     14.59m ±  4%   -5.85% (p=0.002 n=7)
TinyGo/Compile/html.test-10                2.476 ±  5%      2.188 ±  1%  -11.63% (p=0.001 n=7)
TinyGo/Compile/internal_itoa.test-10                       417.6m ±  1%
geomean                                   127.6m           108.0m        -18.34%

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    4.577 ± 1%   4.697 ± 4%  +2.63% (p=0.038 n=7)
Zig/Run/test-opt.wasm-10        18.91 ± 4%   18.96 ± 2%       ~ (p=0.902 n=7)
Zig/Compile/test.wasm-10        5.710 ± 0%   5.707 ± 0%       ~ (p=0.456 n=7)
Zig/Run/test.wasm-10            19.39 ± 1%   19.08 ± 2%  -1.60% (p=0.011 n=7)
geomean                         9.894        9.924       +0.30%

Compiling wazero compiled as Wasm

goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero
               │  old.txt   │              new.txt              │
               │   sec/op   │   sec/op    vs base               │
Compilation-10   3.304 ± 2%   2.533 ± 1%  -23.33% (p=0.001 n=7)

mathetake avatar May 23 '24 03:05 mathetake

fuzzing time 🏃

mathetake avatar May 23 '24 04:05 mathetake