-
Notifications
You must be signed in to change notification settings - Fork 243
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
JIT: skip context switch instructions in function preamble / function call return #173
Comments
mathetake
added a commit
that referenced
this issue
Feb 1, 2022
…lls (#175) This commit refactors the code around function calls/returns and reduces the generated instructions. Notably resolves #173 and skips the module context switch which is supposed to happen on function entry and return. Given that, in almost all use cases, users instantiate single Wasm binary and run the functions from it rather than doing import/export on multiple binaries, the context switch almost never happens. therefore the branch prediction on whether or not skipping context switch code should be almost always correct. As a result, the cost of function calls decreases up to 35% as you can see the bench mark result below where the bench case is "recursive" fibonacci function which is call heavy. =========== name old time/op new time/op delta Engines/jit/fib_for_20-32 105µs ± 3% 70µs ± 3% -33.55% (p=0.008 n=5+5) Engines/jit/fib_for_30-32 13.0ms ± 2% 8.5ms ± 3% -34.89% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Engines/jit/fib_for_20-32 16.0B ± 0% 16.0B ± 0% ~ (all equal) Engines/jit/fib_for_30-32 16.0B ± 0% 16.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Engines/jit/fib_for_20-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) Engines/jit/fib_for_30-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) =========== Overall bench results is as follows: =========== name old time/op new time/op delta Engines/jit/base64_5_per_exec-32 0.00ns ±15% 0.00ns ±44% ~ (p=0.952 n=5+5) Engines/jit/base64_100_per_exec-32 0.00ns ± 7% 0.00ns ±21% ~ (p=0.095 n=5+5) Engines/jit/base64_10000_per_exec-32 0.02ns ±13% 0.02ns ± 7% ~ (p=0.421 n=5+5) Engines/jit/fib_for_5-32 164ns ± 3% 153ns ± 2% -6.68% (p=0.008 n=5+5) Engines/jit/fib_for_10-32 966ns ± 3% 687ns ± 1% -28.86% (p=0.008 n=5+5) Engines/jit/fib_for_20-32 106µs ± 2% 69µs ± 4% -35.30% (p=0.008 n=5+5) Engines/jit/string_manipulation_size_50-32 58.1µs ± 4% 54.2µs ±12% ~ (p=0.151 n=5+5) Engines/jit/string_manipulation_size_100-32 177µs ± 2% 152µs ± 2% -13.93% (p=0.016 n=5+4) Engines/jit/string_manipulation_size_1000-32 12.9ms ± 0% 11.1ms ± 5% -13.44% (p=0.016 n=4+5) Engines/jit/reverse_array_size_500-32 12.0µs ± 3% 10.2µs ± 4% -15.38% (p=0.008 n=5+5) Engines/jit/reverse_array_size_1000-32 23.9µs ± 1% 20.7µs ± 3% -13.60% (p=0.008 n=5+5) Engines/jit/reverse_array_size_10000-32 287µs ±14% 251µs ±11% ~ (p=0.222 n=5+5) Engines/jit/random_mat_mul_size_5-32 21.2µs ±25% 18.7µs ±10% ~ (p=0.222 n=5+5) Engines/jit/random_mat_mul_size_10-32 45.6µs ± 6% 42.1µs ± 3% -7.71% (p=0.016 n=5+4) Engines/jit/random_mat_mul_size_20-32 175µs ± 2% 164µs ± 3% -6.52% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Engines/jit/base64_5_per_exec-32 0.00B 0.00B ~ (all equal) Engines/jit/base64_100_per_exec-32 0.00B 0.00B ~ (all equal) Engines/jit/base64_10000_per_exec-32 0.00B 0.00B ~ (all equal) Engines/jit/fib_for_5-32 16.0B ± 0% 16.0B ± 0% ~ (all equal) Engines/jit/fib_for_10-32 16.0B ± 0% 16.0B ± 0% ~ (all equal) Engines/jit/fib_for_20-32 16.0B ± 0% 16.0B ± 0% ~ (all equal) Engines/jit/string_manipulation_size_50-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/string_manipulation_size_100-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/string_manipulation_size_1000-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/reverse_array_size_500-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/reverse_array_size_1000-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/reverse_array_size_10000-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_5-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_10-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_20-32 8.00B ± 0% 8.00B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Engines/jit/base64_5_per_exec-32 0.00 0.00 ~ (all equal) Engines/jit/base64_100_per_exec-32 0.00 0.00 ~ (all equal) Engines/jit/base64_10000_per_exec-32 0.00 0.00 ~ (all equal) Engines/jit/fib_for_5-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) Engines/jit/fib_for_10-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) Engines/jit/fib_for_20-32 2.00 ± 0% 2.00 ± 0% ~ (all equal) Engines/jit/string_manipulation_size_50-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/string_manipulation_size_100-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/string_manipulation_size_1000-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/reverse_array_size_500-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/reverse_array_size_1000-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/reverse_array_size_10000-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_5-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_10-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) Engines/jit/random_mat_mul_size_20-32 1.00 ± 0% 1.00 ± 0% ~ (all equal) ===========
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: https://github.com/tetratelabs/wazero/blob/main/wasm/jit/jit_amd64.go#L5467-L5468
The text was updated successfully, but these errors were encountered: