Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wazevo(frontend): faster non-imported global access #1889

Merged
merged 5 commits into from
Dec 22, 2023
Merged

Conversation

mathetake
Copy link
Member

@mathetake mathetake commented Dec 21, 2023

This allows the faster access to the non-imported globals. Basically,
this eliminates one load instruction per global.get/set.

In doing so, I changed how to hold global values and wazevo no longer
uses wasm.GlobalInstance.Value field to hold the runtime value of the global.

$ benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/tetratelabs/wazero/internal/integration_test/stdlibs
                                                          │   old.txt   │               new.txt               │
                                                          │   sec/op    │   sec/op     vs base                │
Zig/optimizing/Run/test-opt.wasm-10                          21.22 ± 5%    20.34 ± 5%        ~ (p=0.075 n=10)
Zig/optimizing/Compile/test-opt.wasm-10                      6.715 ± 3%    6.586 ± 2%        ~ (p=0.393 n=10)
Zig/optimizing/Run/test.wasm-10                              22.53 ± 3%    20.84 ± 6%   -7.50% (p=0.002 n=10)
Zig/optimizing/Compile/test.wasm-10                          6.621 ± 5%    6.121 ± 5%   -7.55% (p=0.004 n=10)
TinyGo/optimizing/Run/container_heap.test-10                15.40m ± 4%   14.09m ± 4%   -8.51% (p=0.001 n=7)
TinyGo/optimizing/Compile/container_heap.test-10            493.8m ± 3%   437.3m ± 2%  -11.44% (p=0.001 n=7)
TinyGo/optimizing/Run/container_list.test-10                14.96m ± 0%   13.56m ± 0%   -9.39% (p=0.001 n=7)
TinyGo/optimizing/Compile/container_list.test-10            487.8m ± 4%   434.9m ± 0%  -10.84% (p=0.001 n=7)
TinyGo/optimizing/Run/container_ring.test-10                14.69m ± 4%   13.41m ± 0%   -8.67% (p=0.001 n=7)
TinyGo/optimizing/Compile/container_ring.test-10            479.1m ± 8%   426.3m ± 0%  -11.01% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_des.test-10                    18.16m ± 1%   17.53m ± 0%   -3.48% (p=0.001 n=7)
TinyGo/optimizing/Compile/crypto_des.test-10                467.6m ± 4%   442.0m ± 0%   -5.48% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_md5.test-10                    19.96m ± 2%   19.75m ± 1%        ~ (p=0.456 n=7)
TinyGo/optimizing/Compile/crypto_md5.test-10                472.0m ± 3%   436.9m ± 0%   -7.43% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_rc4.test-10                    167.4m ± 0%   162.8m ± 0%   -2.76% (p=0.001 n=7)
TinyGo/optimizing/Compile/crypto_rc4.test-10                444.6m ± 3%   421.3m ± 0%   -5.24% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_sha1.test-10                   15.86m ± 1%   15.09m ± 0%   -4.85% (p=0.001 n=7)
TinyGo/optimizing/Compile/crypto_sha1.test-10               464.5m ± 2%   436.6m ± 0%   -6.00% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_sha256.test-10                 16.02m ± 3%   15.36m ± 0%   -4.11% (p=0.001 n=7)
TinyGo/optimizing/Compile/crypto_sha256.test-10             454.3m ± 0%   444.9m ± 0%   -2.07% (p=0.001 n=7)
TinyGo/optimizing/Run/crypto_sha512.test-10                 18.46m ± 0%   18.12m ± 0%   -1.80% (p=0.001 n=7)
TinyGo/optimizing/Compile/crypto_sha512.test-10             454.8m ± 0%   448.1m ± 1%   -1.49% (p=0.001 n=7)
TinyGo/optimizing/Run/encoding_ascii85.test-10              14.16m ± 1%   14.11m ± 0%   -0.32% (p=0.017 n=7)
TinyGo/optimizing/Compile/encoding_ascii85.test-10          442.2m ± 0%   436.6m ± 0%   -1.25% (p=0.001 n=7)
TinyGo/optimizing/Run/encoding_base32.test-10               92.23m ± 0%   91.50m ± 0%   -0.80% (p=0.001 n=7)
TinyGo/optimizing/Compile/encoding_base32.test-10           590.8m ± 1%   582.1m ± 0%   -1.46% (p=0.001 n=7)
TinyGo/optimizing/Run/encoding_csv.test-10                  24.34m ± 0%   24.18m ± 0%   -0.64% (p=0.001 n=7)
TinyGo/optimizing/Compile/encoding_csv.test-10              472.9m ± 0%   468.1m ± 1%   -1.02% (p=0.004 n=7)
TinyGo/optimizing/Run/encoding_hex.test-10                  10.13m ± 0%   10.11m ± 1%        ~ (p=0.259 n=7)
TinyGo/optimizing/Compile/encoding_hex.test-10              460.5m ± 2%   452.7m ± 0%   -1.68% (p=0.001 n=7)
TinyGo/optimizing/Run/go_scanner.test-10                    15.99m ± 1%   15.97m ± 0%        ~ (p=0.902 n=7)
TinyGo/optimizing/Compile/go_scanner.test-10                491.1m ± 0%   485.5m ± 1%   -1.15% (p=0.007 n=7)
TinyGo/optimizing/Run/hash.test-10                          15.42m ± 0%   15.52m ± 0%   +0.64% (p=0.001 n=7)
TinyGo/optimizing/Compile/hash.test-10                      574.0m ± 0%   568.1m ± 0%   -1.03% (p=0.001 n=7)
TinyGo/optimizing/Run/hash_adler32.test-10                  23.91m ± 0%   24.67m ± 1%   +3.20% (p=0.001 n=7)
TinyGo/optimizing/Compile/hash_adler32.test-10              426.1m ± 0%   421.5m ± 0%   -1.07% (p=0.001 n=7)
TinyGo/optimizing/Run/hash_crc64.test-10                    16.90m ± 1%   16.84m ± 0%   -0.34% (p=0.001 n=7)
TinyGo/optimizing/Compile/hash_crc64.test-10                536.7m ± 0%   532.0m ± 2%        ~ (p=0.209 n=7)
TinyGo/optimizing/Run/hash_fnv.test-10                      13.94m ± 0%   13.98m ± 0%   +0.25% (p=0.017 n=7)
TinyGo/optimizing/Compile/hash_fnv.test-10                  450.3m ± 0%   445.7m ± 0%   -1.02% (p=0.001 n=7)
TinyGo/optimizing/Run/html.test-10                          15.29m ± 0%   15.32m ± 0%        ~ (p=0.073 n=7)
TinyGo/optimizing/Compile/html.test-10                       3.614 ± 1%    3.580 ± 1%   -0.94% (p=0.004 n=7)
TinyGo/optimizing/Run/internal_itoa.test-10                 13.31m ± 0%   13.32m ± 0%        ~ (p=0.456 n=7)
TinyGo/optimizing/Compile/internal_itoa.test-10             420.5m ± 0%   417.6m ± 0%   -0.69% (p=0.001 n=7)
TinyGo/optimizing/Run/internal_profile.test-10              8.898m ± 0%   8.933m ± 0%   +0.40% (p=0.042 n=7)
TinyGo/optimizing/Compile/internal_profile.test-10          564.1m ± 0%   557.6m ± 1%   -1.14% (p=0.001 n=7)
TinyGo/optimizing/Run/math.test-10                          8.897m ± 1%   8.914m ± 0%        ~ (p=0.165 n=7)
TinyGo/optimizing/Compile/math.test-10                      563.1m ± 2%   556.4m ± 0%   -1.18% (p=0.001 n=7)
TinyGo/optimizing/Run/math_cmplx.test-10                    15.02m ± 0%   15.13m ± 0%   +0.78% (p=0.001 n=7)
TinyGo/optimizing/Compile/math_cmplx.test-10                495.0m ± 2%   489.9m ± 0%   -1.03% (p=0.001 n=7)
TinyGo/optimizing/Run/net.test-10                            1.166 ± 1%    1.165 ± 1%        ~ (p=0.805 n=7)
TinyGo/optimizing/Compile/net.test-10                       504.4m ± 0%   499.1m ± 0%   -1.05% (p=0.001 n=7)
TinyGo/optimizing/Run/net_http_internal_ascii.test-10       13.35m ± 1%   13.36m ± 0%        ~ (p=0.620 n=7)
TinyGo/optimizing/Compile/net_http_internal_ascii.test-10   422.0m ± 0%   417.6m ± 0%   -1.05% (p=0.001 n=7)
TinyGo/optimizing/Run/net_mail.test-10                      13.88m ± 1%   13.90m ± 1%        ~ (p=0.620 n=7)
TinyGo/optimizing/Compile/net_mail.test-10                  575.6m ± 0%   574.6m ± 2%        ~ (p=0.318 n=7)
TinyGo/optimizing/Run/os.test-10                            10.49m ± 1%   10.52m ± 1%        ~ (p=0.383 n=7)
TinyGo/optimizing/Compile/os.test-10                        537.1m ± 1%   533.3m ± 0%   -0.70% (p=0.001 n=7)
TinyGo/optimizing/Run/path.test-10                          14.01m ± 1%   14.00m ± 0%        ~ (p=0.805 n=7)
TinyGo/optimizing/Compile/path.test-10                      433.3m ± 0%   429.6m ± 0%   -0.86% (p=0.001 n=7)
TinyGo/optimizing/Run/reflect.test-10                       35.65m ± 0%   36.06m ± 2%   +1.15% (p=0.001 n=7)
TinyGo/optimizing/Compile/reflect.test-10                   604.1m ± 0%   598.9m ± 0%   -0.87% (p=0.001 n=7)
TinyGo/optimizing/Run/sync.test-10                          10.82m ± 1%   10.83m ± 1%        ~ (p=0.620 n=7)
TinyGo/optimizing/Compile/sync.test-10                      442.3m ± 0%   439.0m ± 2%   -0.74% (p=0.026 n=7)
TinyGo/optimizing/Run/testing.test-10                        4.413 ± 2%    4.446 ± 1%        ~ (p=0.073 n=7)
TinyGo/optimizing/Compile/testing.test-10                   479.3m ± 1%   474.4m ± 0%   -1.02% (p=0.001 n=7)
TinyGo/optimizing/Run/testing_iotest.test-10                14.29m ± 0%   14.27m ± 0%        ~ (p=0.535 n=7)
TinyGo/optimizing/Compile/testing_iotest.test-10            461.0m ± 0%   456.4m ± 3%   -1.01% (p=0.026 n=7)
TinyGo/optimizing/Run/text_scanner.test-10                  17.92m ± 0%   17.88m ± 1%        ~ (p=0.383 n=7)
TinyGo/optimizing/Compile/text_scanner.test-10              472.1m ± 1%   467.1m ± 1%   -1.06% (p=0.007 n=7)
TinyGo/optimizing/Run/unicode.test-10                       14.23m ± 0%   14.28m ± 0%   +0.34% (p=0.011 n=7)
TinyGo/optimizing/Compile/unicode.test-10                   447.1m ± 0%   443.4m ± 0%   -0.83% (p=0.001 n=7)
TinyGo/optimizing/Run/unicode_utf16.test-10                 6.723m ± 0%   6.739m ± 0%        ~ (p=0.053 n=7)
TinyGo/optimizing/Compile/unicode_utf16.test-10             461.8m ± 0%   458.4m ± 0%   -0.74% (p=0.001 n=7)
TinyGo/optimizing/Run/unicode_utf8.test-10                  14.97m ± 0%   15.03m ± 0%   +0.44% (p=0.011 n=7)
TinyGo/optimizing/Compile/unicode_utf8.test-10              441.5m ± 0%   437.1m ± 1%   -1.01% (p=0.011 n=7)
geomean                                                     135.9m        133.2m        -1.99%

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
@mathetake
Copy link
Member Author

found a bug not covered by the existing ad_hoc test so I need to add one, and after that, will run fuzzing

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
@mathetake
Copy link
Member Author

now fuzzing 🏃

@mathetake mathetake changed the title wazevo(frontend): faster local global access wazevo(frontend): faster non-imported global access Dec 22, 2023
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
@mathetake mathetake marked this pull request as ready for review December 22, 2023 02:21
@mathetake
Copy link
Member Author

will wait for fuzzing to finish till tomorrow

@mathetake mathetake merged commit 2762404 into main Dec 22, 2023
56 checks passed
@mathetake mathetake deleted the globalfaster branch December 22, 2023 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant