Skip to content

Commit

Permalink
[executor-benchmark] Simple script loading benchmark (#15098)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov authored Nov 5, 2024
1 parent d79e765 commit ab2bd8c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 6 deletions.
2 changes: 2 additions & 0 deletions crates/transaction-generator-lib/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub enum TransactionTypeArg {
SmartTablePicture1BWith256Change,
SmartTablePicture1MWith1KChangeExceedsLimit,
DeserializeU256,
SimpleScript,
}

impl TransactionTypeArg {
Expand Down Expand Up @@ -318,6 +319,7 @@ impl TransactionTypeArg {
})
},
TransactionTypeArg::DeserializeU256 => call_custom_module(EntryPoints::DeserializeU256),
TransactionTypeArg::SimpleScript => call_custom_module(EntryPoints::SimpleScript),
}
}

Expand Down
19 changes: 15 additions & 4 deletions crates/transaction-generator-lib/src/publishing/module_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
#![allow(unused)]

use crate::publishing::publish_util::Package;
use aptos_framework::natives::code::{MoveOption, PackageMetadata};
use aptos_sdk::{
bcs,
Expand All @@ -11,7 +12,7 @@ use aptos_sdk::{
},
types::{
serde_helper::bcs_utils::bcs_size_of_byte_array,
transaction::{EntryFunction, TransactionPayload},
transaction::{EntryFunction, Script, TransactionPayload},
},
};
use move_binary_format::{
Expand Down Expand Up @@ -267,6 +268,10 @@ pub enum EntryPoints {
num_points_per_txn: usize,
},
DeserializeU256,
/// No-op script with dependencies in *::simple.move. The script has unreachable code that is
/// there to slow down deserialization & verification, effectively making it more expensive to
/// load it into code cache.
SimpleScript,
}

impl EntryPoints {
Expand All @@ -291,7 +296,8 @@ impl EntryPoints {
| EntryPoints::BytesMakeOrChange { .. }
| EntryPoints::EmitEvents { .. }
| EntryPoints::MakeOrChangeTable { .. }
| EntryPoints::MakeOrChangeTableRandom { .. } => "simple",
| EntryPoints::MakeOrChangeTableRandom { .. }
| EntryPoints::SimpleScript => "simple",
EntryPoints::IncGlobal
| EntryPoints::IncGlobalAggV2
| EntryPoints::ModifyGlobalBoundedAggV2 { .. }
Expand Down Expand Up @@ -347,7 +353,8 @@ impl EntryPoints {
| EntryPoints::BytesMakeOrChange { .. }
| EntryPoints::EmitEvents { .. }
| EntryPoints::MakeOrChangeTable { .. }
| EntryPoints::MakeOrChangeTableRandom { .. } => "simple",
| EntryPoints::MakeOrChangeTableRandom { .. }
| EntryPoints::SimpleScript => "simple",
EntryPoints::IncGlobal
| EntryPoints::IncGlobalAggV2
| EntryPoints::ModifyGlobalBoundedAggV2 { .. } => "aggregator_example",
Expand Down Expand Up @@ -411,6 +418,9 @@ impl EntryPoints {
},
EntryPoints::Double => get_payload_void(module_id, ident_str!("double").to_owned()),
EntryPoints::Half => get_payload_void(module_id, ident_str!("half").to_owned()),
EntryPoints::SimpleScript => {
Package::script(*other.expect("Must provide sender's address"))
},
// 1 arg
EntryPoints::Loop {
loop_count,
Expand Down Expand Up @@ -791,7 +801,8 @@ impl EntryPoints {
| EntryPoints::BytesMakeOrChange { .. }
| EntryPoints::EmitEvents { .. }
| EntryPoints::MakeOrChangeTable { .. }
| EntryPoints::MakeOrChangeTableRandom { .. } => AutomaticArgs::Signer,
| EntryPoints::MakeOrChangeTableRandom { .. }
| EntryPoints::SimpleScript => AutomaticArgs::Signer,
EntryPoints::Nop2Signers | EntryPoints::Nop5Signers => AutomaticArgs::SignerAndMultiSig,
EntryPoints::IncGlobal
| EntryPoints::IncGlobalAggV2
Expand Down
25 changes: 23 additions & 2 deletions crates/transaction-generator-lib/src/publishing/publish_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ use aptos_sdk::{
transaction_builder::{aptos_stdlib, TransactionFactory},
types::{
account_address::AccountAddress,
transaction::{SignedTransaction, TransactionPayload},
transaction::{Script, SignedTransaction, TransactionPayload},
LocalAccount,
},
};
use move_binary_format::{access::ModuleAccess, file_format::SignatureToken, CompiledModule};
use move_binary_format::{
access::ModuleAccess,
file_format::{CompiledScript, SignatureToken},
CompiledModule,
};
use rand::{rngs::StdRng, Rng};

// Information used to track a publisher and what allows to identify and
Expand Down Expand Up @@ -127,6 +131,23 @@ impl Package {
Self::Simple(modules, metadata)
}

pub fn script(publisher: AccountAddress) -> TransactionPayload {
let code = &*raw_module_data::SCRIPT_SIMPLE;
let mut script = CompiledScript::deserialize(code).expect("Script must deserialize");

// Change the constant to the sender's address to change script's hash.
for constant in &mut script.constant_pool {
if constant.type_ == SignatureToken::Address {
constant.data = bcs::to_bytes(&publisher).expect("Address must serialize");
break;
}
}

let mut code = vec![];
script.serialize(&mut code).expect("Script must serialize");
TransactionPayload::Script(Script::new(code, vec![], vec![]))
}

fn load_package(
package_bytes: &[u8],
modules_bytes: &[Vec<u8>],
Expand Down
10 changes: 10 additions & 0 deletions crates/transaction-generator-lib/src/publishing/raw_module_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,16 @@ pub static PACKAGE_SIMPLE_METADATA: Lazy<Vec<u8>> = Lazy::new(|| {
]
});

#[rustfmt::skip]
pub static SCRIPT_SIMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
161, 28, 235, 11, 7, 0, 0, 10, 2, 5, 0, 4, 6, 4, 34, 1, 6, 12,
0, 5, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 1, 3, 11, 0, 1, 2,
]
});

#[rustfmt::skip]
pub static MODULE_SIMPLE_SIMPLE: Lazy<Vec<u8>> = Lazy::new(|| {
vec![
Expand Down
17 changes: 17 additions & 0 deletions testsuite/module-publish/src/packages/simple/scripts/main.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
script {
// Note: this constant can be replaced in compiled script to make it hash to a different value.
const SENDER: address = @0x1;

fun main(sender: &signer) {
// The idea is to to ensure that this script takes some time to be deserialized and verified, but the actual
// execution time is small (no-op).
if (false) {
0xABCD::simple::loop_nop(sender, 0);
0xABCD::simple::loop_arithmetic(sender, 0);
0xABCD::simple::loop_bcs(sender, 0, 0);
if (false) {
while (true) {}
}
}
}
}
2 changes: 2 additions & 0 deletions testsuite/single_node_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class RunGroupConfig:
RunGroupConfig(expected_tps=6800, key=RunGroupKey("token-v2-ambassador-mint"), included_in=Flow.MAINNET_LARGE_DB),
# RunGroupConfig(expected_tps=17000 if NUM_ACCOUNTS < 5000000 else 28000, key=RunGroupKey("coin_transfer_connected_components", executor_type="sharded"), key_extra=RunGroupKeyExtra(sharding_traffic_flags="--connected-tx-grps 5000", transaction_type_override=""), included_in=Flow.MAINNET | Flow.MAINNET_LARGE_DB, waived=True),
# RunGroupConfig(expected_tps=27000 if NUM_ACCOUNTS < 5000000 else 23000, key=RunGroupKey("coin_transfer_hotspot", executor_type="sharded"), key_extra=RunGroupKeyExtra(sharding_traffic_flags="--hotspot-probability 0.8", transaction_type_override=""), included_in=Flow.MAINNET | Flow.MAINNET_LARGE_DB, waived=True),

RunGroupConfig(expected_tps=1000, key=RunGroupKey("simple-script"), included_in=LAND_BLOCKING_AND_C, waived=True),
]
# fmt: on

Expand Down

0 comments on commit ab2bd8c

Please sign in to comment.