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

Tweak/wasm costing #1978

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft

Tweak/wasm costing #1978

wants to merge 4 commits into from

Conversation

lrubasze
Copy link
Contributor

Summary

INSTRUCTIONS:
Add summary - one or two sentences explaining the purpose of this PR.

Details

INSTRUCTIONS:
Provide further details about the changes, or how they fit into the roadmap.
You can delete this section if it's not useful.

Testing

INSTRUCTIONS:
Further details about the tests you've added or manually performed.
You can delete this section if it's not useful.

Update Recommendations

INSTRUCTIONS:
This section is to provide recommendations to consumers of this repo about how they
should handle breaking changes, or integrate new features. The two key stakeholder
groups are dApp Developers and Internal Integrators, and there are separate sections
for each.

In order to allow us to compile aggregated update instructions across PRs, please tag the PR
with 0+ of the relevant labels:
* scrypto-lib - Any change to the scrypto library
* sbor - Any breaking change to SBOR encoding/decoding
* manifest - Any change to manifest display, compilation/decompilation
* transaction - Any change which affects the compiled manifest, or transaction semantics
* substate - Any change to substates, the state model, or what's stored in the DB
* native-blueprint-interface - Any change to the interface of native blueprints
* files-moved - Any change to where engine types have moved, which will require
  internal integrators to update their imports

If you have a breaking change which doesn't fix into a category above, then tag it with
the closest label, and discuss in slack/discord.

If your PR contains no breaking changes or new features or hasn't been tagged, this whole
section can be deleted.

For dApp Developers

INSTRUCTIONS:
Migration recommendations for a dApp developer to update their dApp/integrations
due to to the change/s in this PR.

These will be aggregated by the Developer Ecosystem team and included in the next Scrypto migration guide
(eg https://docs-babylon.radixdlt.com/main/scrypto/release_notes/migrating_from_0.7_to_0.8.html )

For Internal Integrators

INSTRUCTIONS:
Instructions to any internal integrations (eg Node, Toolkit, Gateway, Ledger App) for how the changes may affect
them and recommendations for how they should update to support this change.

Copy link

github-actions bot commented Oct 25, 2024

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

Copy link

Benchmark for ed53e7b

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 45.5±0.19ms 45.4±0.25ms -0.22%
costing::decode_encoded_i8_array_to_manifest_raw_value 19.5±0.11ms 19.7±0.06ms +1.03%
costing::decode_encoded_i8_array_to_manifest_value 41.8±0.11ms 41.7±0.14ms -0.24%
costing::decode_encoded_tuple_array_to_manifest_raw_value 63.2±0.24ms 63.4±0.16ms +0.32%
costing::decode_encoded_tuple_array_to_manifest_value 120.6±1.22ms 120.8±1.06ms +0.17%
costing::decode_encoded_u8_array_to_manifest_raw_value 32.2±0.13µs 31.9±0.29µs -0.93%
costing::decode_encoded_u8_array_to_manifest_value 41.6±0.15ms 41.6±0.08ms 0.00%
costing::decode_rpd_to_manifest_raw_value 12.3±0.05µs 12.4±0.05µs +0.81%
costing::decode_rpd_to_manifest_value 11.1±0.04µs 10.8±0.03µs -2.70%
costing::deserialize_wasm 1210.0±5.39µs 1219.4±8.50µs +0.78%
costing::execute_transaction_creating_big_vec_substates 691.0±7.53ms 693.6±9.04ms +0.38%
costing::execute_transaction_reading_big_vec_substates 581.7±1.56ms 599.9±2.06ms +3.13%
costing::instantiate_flash_loan 904.1±425.86µs 982.9±1006.97µs +8.72%
costing::instantiate_radiswap 998.6±1269.91µs 1285.1±2751.99µs +28.69%
costing::spin_loop 18.3±0.06ms 18.0±0.07ms -1.64%
costing::spin_loop_v2 2.7±0.01s 1029.1±4.79ms -61.89%
costing::spin_loop_v3 630.1±8.53ms 575.5±1.90ms -8.67%
costing::validate_sbor_payload 29.0±0.06µs 30.6±0.11µs +5.52%
costing::validate_sbor_payload_bytes 254.1±1.41ns 243.9±1.21ns -4.01%
costing::validate_secp256k1 77.0±0.34µs 76.7±0.12µs -0.39%
costing::validate_wasm 34.0±0.10ms 34.3±0.12ms +0.88%
decimal::add/0 8.4±0.01ns 8.4±0.01ns 0.00%
decimal::add/rust-native 9.9±0.02ns 9.9±0.01ns 0.00%
decimal::add/wasmi 220.5±0.69ns 223.1±0.63ns +1.18%
decimal::add/wasmi-call-native 2.1±0.00µs 2.1±0.01µs 0.00%
decimal::div/0 166.4±0.28ns 165.6±0.31ns -0.48%
decimal::from_string/0 163.4±0.53ns 163.9±0.81ns +0.31%
decimal::mul/0 127.5±0.29ns 127.0±0.09ns -0.39%
decimal::mul/rust-native 123.7±0.39ns 123.8±0.33ns +0.08%
decimal::mul/wasmi 11.1±0.06µs 10.9±0.14µs -1.80%
decimal::mul/wasmi-call-native 2.2±0.01µs 2.2±0.01µs 0.00%
decimal::pow/0 580.2±1.18ns 579.7±1.63ns -0.09%
decimal::pow/rust-native 577.1±1.35ns 577.1±0.32ns 0.00%
decimal::pow/wasmi 58.2±0.46µs 57.7±0.25µs -0.86%
decimal::pow/wasmi-call-native 3.2±0.00µs 3.2±0.00µs 0.00%
decimal::root/0 8.2±0.02µs 8.3±0.01µs +1.22%
decimal::sub/0 8.3±0.03ns 8.2±0.02ns -1.20%
decimal::to_string/0 443.8±0.59ns 441.2±1.03ns -0.59%
large_transaction_processing::prepare 2.4±0.01ms 2.4±0.00ms 0.00%
large_transaction_processing::prepare_and_decompile 6.3±0.01ms 6.3±0.02ms 0.00%
large_transaction_processing::prepare_and_decompile_and_recompile 26.5±1.88ms 28.4±2.98ms +7.17%
metadata_validation::validate_urls 4.7±0.04µs 4.8±0.02µs +2.13%
precise_decimal::add/0 9.0±0.03ns 9.0±0.02ns 0.00%
precise_decimal::add/rust-native 11.0±0.22ns 10.8±0.11ns -1.82%
precise_decimal::add/wasmi 276.2±0.55ns 275.3±0.67ns -0.33%
precise_decimal::add/wasmi-call-native 2.8±0.00µs 2.8±0.01µs 0.00%
precise_decimal::div/0 284.7±3.81ns 285.7±3.81ns +0.35%
precise_decimal::from_string/0 203.4±0.84ns 203.5±0.25ns +0.05%
precise_decimal::mul/0 322.0±0.96ns 320.7±0.48ns -0.40%
precise_decimal::mul/rust-native 292.3±1.37ns 278.2±0.89ns -4.82%
precise_decimal::mul/wasmi 33.3±0.15µs 33.0±0.58µs -0.90%
precise_decimal::mul/wasmi-call-native 3.1±0.01µs 3.2±0.01µs +3.23%
precise_decimal::pow/0 1704.8±2.78ns 1699.9±6.52ns -0.29%
precise_decimal::pow/rust-native 1371.7±3.45ns 1322.9±3.14ns -3.56%
precise_decimal::pow/wasmi 163.6±0.91µs 160.9±1.25µs -1.65%
precise_decimal::pow/wasmi-call-native 5.3±0.02µs 5.3±0.01µs 0.00%
precise_decimal::root/0 58.0±0.14µs 57.1±0.06µs -1.55%
precise_decimal::sub/0 9.2±0.08ns 9.2±0.05ns 0.00%
precise_decimal::to_string/0 713.4±3.27ns 701.3±2.47ns -1.70%
schema::validate_payload 396.5±1.18µs 385.2±1.33µs -2.85%
transaction::radiswap 4.8±0.03ms 4.8±0.04ms 0.00%
transaction::transfer 1849.0±10.65µs 1848.7±6.41µs -0.02%
transaction_validation::validate_manifest 43.2±0.12µs 43.3±0.24µs +0.23%
transaction_validation::verify_bls_2KB 1015.3±23.98µs 1042.1±31.23µs +2.64%
transaction_validation::verify_bls_32B 1015.9±23.35µs 1011.7±16.90µs -0.41%
transaction_validation::verify_ecdsa 74.7±0.22µs 74.6±0.07µs -0.13%
transaction_validation::verify_ed25519 42.4±0.12µs 42.6±0.18µs +0.47%


wasm_execution_units / 3000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something here doesn't seem right -
1 / 0.00028877714 = 3462 which rounded down to 3000
1 / 0.0003709 = 2696 which would round down to 2500, not 4000

That said, using 2500 would make wasm more expensive. Maybe a few more of us should run this to provide a larger sample size?

// Add 10,000 base units to make sure the we do not undercharge for WASM execution,
// which might lead to system exploitation.
// This is especially important in corner-cases such as `costing::spin_loop_v2` benchmark.
let n = n + 10_000;
Copy link
Contributor

@dhedey dhedey Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels to me slightly better to put this in consume_wasm_execution_units rather than the wasmi adaptor.

Also this would need to be dependent on the VmVersion

... and ideally statically so we don't introduce a branch in every call in this critical code path. I'm not quite sure how we'd do this, but there are a few options.

Perhaps ScryptoRuntime takes a new generic parameter - we create a new one each invocation, so we can just switch on vm_api.get_scrypto_version() and either create a ScryptoRuntime::<FeeBehaviour1, _>::new or a ScryptoRuntime::<FeeBehaviour2, _>::new (@iamyulong - similar in idea to #1919 but at the VM layer - if VmApi had an associated type which impls VersionedVmLogic then we wouldn't need a match here)

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.

2 participants