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

Add base cost to consume_wasm_execution_units host function #1978

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

lrubasze
Copy link
Contributor

@lrubasze lrubasze commented Oct 25, 2024

Summary

Added WASM execution unit base to assure simple WASM calls are not being undercharged.

Motivation

Test Base PR %
costing::scrypto_malloc 592.2±0.84ms 504.3±2.87ms -14.84%
costing::scrypto_sbor_decode 569.5±1.32ms 500.3±2.76ms -12.15%
costing::scrypto_sha256 392.4±1.20ms 367.5±1.57ms -6.35%
costing::spin_loop_v1 628.2±5.74ms 474.9±2.19ms -24.40%
costing::spin_loop_v2 2.7±0.00s 959.4±0.90ms -64.47%

Based on the benchmarks on the base, the spin_loop_v2 does not finish within 1 second, despite consuming around 100 million execution cost units.

It's made possible by iterating an empty code block (except a br instruction), where consume_wasm_execution_units host function becomes the dominant factor.

This PR fixes it by introducing a base cost to account for the execution of the host function itself.

Copy link

github-actions bot commented Oct 25, 2024

Docker tags
docker.io/radixdlt/private-scrypto-builder:4af62f6941

Copy link

github-actions bot commented Oct 25, 2024

Benchmark for 4af62f6

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 44.3±0.09ms 44.4±0.16ms +0.23%
costing::decode_encoded_i8_array_to_manifest_raw_value 19.3±0.02ms 19.4±0.05ms +0.52%
costing::decode_encoded_i8_array_to_manifest_value 41.5±0.09ms 41.7±0.09ms +0.48%
costing::decode_encoded_tuple_array_to_manifest_raw_value 61.3±0.31ms 61.0±0.18ms -0.49%
costing::decode_encoded_tuple_array_to_manifest_value 99.0±0.29ms 99.5±0.22ms +0.51%
costing::decode_encoded_u8_array_to_manifest_raw_value 32.4±0.08µs 25.8±0.08µs -20.37%
costing::decode_encoded_u8_array_to_manifest_value 41.6±0.12ms 41.7±0.13ms +0.24%
costing::decode_rpd_to_manifest_raw_value 12.7±0.02µs 12.8±0.04µs +0.79%
costing::decode_rpd_to_manifest_value 10.8±0.08µs 10.9±0.04µs +0.93%
costing::deserialize_wasm 1207.2±5.18µs 1206.6±8.31µs -0.05%
costing::execute_transaction_creating_big_vec_substates 696.7±8.52ms 696.3±8.88ms -0.06%
costing::execute_transaction_reading_big_vec_substates 580.0±1.22ms 685.3±2.35ms +18.16%
costing::instantiate_flash_loan 859.3±400.90µs 1024.2±1035.07µs +19.19%
costing::instantiate_radiswap 933.6±630.53µs 917.9±463.35µs -1.68%
costing::scrypto_malloc 595.7±0.71ms 498.4±0.58ms -16.33%
costing::scrypto_sbor_decode 560.2±1.64ms 489.4±0.89ms -12.64%
costing::scrypto_sha256 390.7±1.36ms 359.9±0.69ms -7.88%
costing::spin_loop_v1 614.6±0.74ms 476.5±7.74ms -22.47%
costing::spin_loop_v2 2.7±0.15s 953.4±0.68ms -64.69%
costing::validate_sbor_payload 30.3±0.09µs 32.0±0.09µs +5.61%
costing::validate_sbor_payload_bytes 251.5±0.82ns 252.5±1.89ns +0.40%
costing::validate_secp256k1 76.7±0.81µs 76.7±0.07µs 0.00%
costing::validate_wasm 33.4±0.03ms 33.5±0.07ms +0.30%
decimal::add/0 8.4±0.00ns 8.4±0.00ns 0.00%
decimal::add/rust-native 9.8±0.00ns 9.8±0.00ns 0.00%
decimal::add/wasmi 220.3±0.27ns 219.2±0.30ns -0.50%
decimal::add/wasmi-call-native 2.1±0.00µs 2.1±0.01µs 0.00%
decimal::div/0 169.0±0.24ns 168.4±0.13ns -0.36%
decimal::from_string/0 155.8±0.09ns 155.9±0.13ns +0.06%
decimal::mul/0 129.3±0.11ns 129.0±0.24ns -0.23%
decimal::mul/rust-native 127.4±0.18ns 125.8±0.29ns -1.26%
decimal::mul/wasmi 11.6±0.10µs 11.7±0.10µs +0.86%
decimal::mul/wasmi-call-native 2.3±0.00µs 2.2±0.00µs -4.35%
decimal::pow/0 593.5±0.23ns 592.6±0.49ns -0.15%
decimal::pow/rust-native 589.9±0.38ns 589.1±0.41ns -0.14%
decimal::pow/wasmi 61.1±0.40µs 58.0±0.72µs -5.07%
decimal::pow/wasmi-call-native 3.2±0.00µs 3.2±0.00µs 0.00%
decimal::root/0 8.2±0.01µs 8.1±0.01µs -1.22%
decimal::sub/0 8.3±0.01ns 8.3±0.01ns 0.00%
decimal::to_string/0 446.2±0.28ns 444.7±0.90ns -0.34%
large_transaction_processing::prepare 2.5±0.00ms 2.6±0.00ms +4.00%
large_transaction_processing::prepare_and_decompile 6.3±0.03ms 6.2±0.03ms -1.59%
large_transaction_processing::prepare_and_decompile_and_recompile 28.2±2.15ms 28.9±2.26ms +2.48%
metadata_validation::validate_urls 4.8±0.02µs 4.7±0.09µs -2.08%
precise_decimal::add/0 8.8±0.26ns 8.9±0.00ns +1.14%
precise_decimal::add/rust-native 11.0±0.13ns 10.8±0.12ns -1.82%
precise_decimal::add/wasmi 286.7±0.73ns 277.2±0.56ns -3.31%
precise_decimal::add/wasmi-call-native 2.9±0.00µs 2.8±0.00µs -3.45%
precise_decimal::div/0 286.0±1.15ns 288.2±0.56ns +0.77%
precise_decimal::from_string/0 203.1±0.13ns 202.1±0.46ns -0.49%
precise_decimal::mul/0 330.4±2.16ns 331.7±0.43ns +0.39%
precise_decimal::mul/rust-native 304.5±1.30ns 287.9±0.28ns -5.45%
precise_decimal::mul/wasmi 35.0±0.08µs 33.9±0.25µs -3.14%
precise_decimal::mul/wasmi-call-native 3.1±0.01µs 3.1±0.01µs 0.00%
precise_decimal::pow/0 1737.7±3.31ns 1738.5±5.98ns +0.05%
precise_decimal::pow/rust-native 1375.7±2.60ns 1366.0±5.25ns -0.71%
precise_decimal::pow/wasmi 167.4±0.46µs 162.9±0.90µs -2.69%
precise_decimal::pow/wasmi-call-native 5.4±0.01µs 5.3±0.02µs -1.85%
precise_decimal::root/0 57.9±0.04µs 57.1±0.06µs -1.38%
precise_decimal::sub/0 8.9±0.02ns 9.2±0.02ns +3.37%
precise_decimal::to_string/0 696.1±0.26ns 695.9±1.15ns -0.03%
schema::validate_payload 382.5±0.55µs 386.2±0.48µs +0.97%
transaction::radiswap 4.8±0.02ms 4.8±0.02ms 0.00%
transaction::transfer 1805.0±4.76µs 1804.6±14.21µs -0.02%
transaction_validation::validate_manifest 43.2±0.04µs 43.0±0.03µs -0.46%
transaction_validation::verify_bls_2KB 1044.2±29.77µs 1004.6±7.61µs -3.79%
transaction_validation::verify_bls_32B 1033.5±30.59µs 1050.7±32.06µs +1.66%
transaction_validation::verify_ecdsa 74.4±0.07µs 74.5±0.07µs +0.13%
transaction_validation::verify_ed25519 46.8±0.09µs 42.3±0.08µs -9.62%

@lrubasze lrubasze force-pushed the tweak/wasm-costing branch 2 times, most recently from 51995b2 to 9ff6fc8 Compare October 28, 2024 22:40
@lrubasze lrubasze changed the base branch from develop to feature/bench-scrypto-sbor October 28, 2024 22:41
@lrubasze lrubasze changed the base branch from feature/bench-scrypto-sbor to develop October 29, 2024 09:15
@lrubasze lrubasze force-pushed the tweak/wasm-costing branch 2 times, most recently from 3b9c893 to 59c0797 Compare October 29, 2024 11:01
@lrubasze lrubasze marked this pull request as ready for review October 29, 2024 11:10
@iamyulong iamyulong changed the title Tweak/wasm costing Add base cost to consume_wasm_execution_units host function Oct 29, 2024
@lrubasze lrubasze merged commit cd3006d into develop Oct 29, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants