Skip to content

Commit bc0d7d5

Browse files
authored
perf(vm): Fix VM performance regression on CI loadtest (matter-labs#2782)
## What ❔ Fixes VM performance regression on CI loadtest introduced in matter-labs#2760. ## Why ❔ Changes in the VM interface made the VM eagerly clone compressed bytecodes if compression hasn't failed. Compressed bytecodes aren't used during sandboxed VM execution in the API server (the sandbox only checks that compression is successful).For new VMs, bytecodes can be borrowed from the VM state, which is what this PR does using `Cow`. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`.
1 parent 4a4d87e commit bc0d7d5

File tree

30 files changed

+118
-72
lines changed

30 files changed

+118
-72
lines changed

.github/workflows/ci-core-reusable.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ jobs:
8787
8888
- name: Loadtest configuration
8989
run: |
90-
echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'new' && 22000 || 16000 }} >> .env
91-
echo ACCOUNTS_AMOUNT="150" >> .env
90+
echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'new' && 21000 || 16000 }} >> .env
91+
echo ACCOUNTS_AMOUNT="100" >> .env
92+
echo MAX_INFLIGHT_TXS="10" >> .env
93+
echo SYNC_API_REQUESTS_LIMIT="15" >> .env
9294
echo FAIL_FAST=true >> .env
9395
echo IN_DOCKER=1 >> .env
9496
echo DATABASE_MERKLE_TREE_MODE=lightweight >> .env
@@ -112,7 +114,8 @@ jobs:
112114
- name: Run server
113115
run: |
114116
EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE=${{ matrix.vm_mode }} \
115-
PASSED_ENV_VARS="EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE" \
117+
CHAIN_MEMPOOL_DELAY_INTERVAL=50 \
118+
PASSED_ENV_VARS="EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE,CHAIN_MEMPOOL_DELAY_INTERVAL" \
116119
ci_run zk server --uring --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log &
117120
ci_run sleep 60
118121

core/lib/multivm/src/versions/shadow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ where
7777
tracer: Self::TracerDispatcher,
7878
tx: Transaction,
7979
with_compression: bool,
80-
) -> (BytecodeCompressionResult, VmExecutionResultAndLogs) {
80+
) -> (BytecodeCompressionResult<'_>, VmExecutionResultAndLogs) {
8181
let tx_hash = tx.hash();
8282
let main_result = self.main.inspect_transaction_with_bytecode_compression(
8383
tracer,

core/lib/multivm/src/versions/vm_1_3_2/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
8383
tracer: Self::TracerDispatcher,
8484
tx: Transaction,
8585
with_compression: bool,
86-
) -> (BytecodeCompressionResult, VmExecutionResultAndLogs) {
86+
) -> (BytecodeCompressionResult<'_>, VmExecutionResultAndLogs) {
8787
if let Some(storage_invocations) = tracer.storage_invocations {
8888
self.vm
8989
.execution_mode
@@ -156,7 +156,7 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
156156
result,
157157
)
158158
} else {
159-
(Ok(compressed_bytecodes), result)
159+
(Ok(compressed_bytecodes.into()), result)
160160
}
161161
}
162162

core/lib/multivm/src/versions/vm_1_4_1/bootloader_state/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ impl BootloaderState {
191191
l2_block.first_tx_index + l2_block.txs.len()
192192
}
193193

194-
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> Vec<CompressedBytecodeInfo> {
194+
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> &[CompressedBytecodeInfo] {
195195
if let Some(tx) = self.last_l2_block().txs.last() {
196-
tx.compressed_bytecodes.clone()
196+
&tx.compressed_bytecodes
197197
} else {
198-
vec![]
198+
&[]
199199
}
200200
}
201201

core/lib/multivm/src/versions/vm_1_4_1/vm.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
105105
tracer: Self::TracerDispatcher,
106106
tx: Transaction,
107107
with_compression: bool,
108-
) -> (BytecodeCompressionResult, VmExecutionResultAndLogs) {
108+
) -> (BytecodeCompressionResult<'_>, VmExecutionResultAndLogs) {
109109
self.push_transaction_with_compression(tx, with_compression);
110110
let result = self.inspect_inner(tracer, VmExecutionMode::OneTx, None);
111111
if self.has_unpublished_bytecodes() {
@@ -115,7 +115,10 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
115115
)
116116
} else {
117117
(
118-
Ok(self.bootloader_state.get_last_tx_compressed_bytecodes()),
118+
Ok(self
119+
.bootloader_state
120+
.get_last_tx_compressed_bytecodes()
121+
.into()),
119122
result,
120123
)
121124
}

core/lib/multivm/src/versions/vm_1_4_2/bootloader_state/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ impl BootloaderState {
191191
l2_block.first_tx_index + l2_block.txs.len()
192192
}
193193

194-
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> Vec<CompressedBytecodeInfo> {
194+
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> &[CompressedBytecodeInfo] {
195195
if let Some(tx) = self.last_l2_block().txs.last() {
196-
tx.compressed_bytecodes.clone()
196+
&tx.compressed_bytecodes
197197
} else {
198-
vec![]
198+
&[]
199199
}
200200
}
201201

core/lib/multivm/src/versions/vm_1_4_2/vm.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
105105
tracer: Self::TracerDispatcher,
106106
tx: Transaction,
107107
with_compression: bool,
108-
) -> (BytecodeCompressionResult, VmExecutionResultAndLogs) {
108+
) -> (BytecodeCompressionResult<'_>, VmExecutionResultAndLogs) {
109109
self.push_transaction_with_compression(tx, with_compression);
110110
let result = self.inspect_inner(tracer, VmExecutionMode::OneTx, None);
111111
if self.has_unpublished_bytecodes() {
@@ -115,7 +115,10 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
115115
)
116116
} else {
117117
(
118-
Ok(self.bootloader_state.get_last_tx_compressed_bytecodes()),
118+
Ok(self
119+
.bootloader_state
120+
.get_last_tx_compressed_bytecodes()
121+
.into()),
119122
result,
120123
)
121124
}

core/lib/multivm/src/versions/vm_boojum_integration/bootloader_state/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ impl BootloaderState {
191191
l2_block.first_tx_index + l2_block.txs.len()
192192
}
193193

194-
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> Vec<CompressedBytecodeInfo> {
194+
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> &[CompressedBytecodeInfo] {
195195
if let Some(tx) = self.last_l2_block().txs.last() {
196-
tx.compressed_bytecodes.clone()
196+
&tx.compressed_bytecodes
197197
} else {
198-
vec![]
198+
&[]
199199
}
200200
}
201201

core/lib/multivm/src/versions/vm_boojum_integration/vm.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
106106
tracer: Self::TracerDispatcher,
107107
tx: Transaction,
108108
with_compression: bool,
109-
) -> (BytecodeCompressionResult, VmExecutionResultAndLogs) {
109+
) -> (BytecodeCompressionResult<'_>, VmExecutionResultAndLogs) {
110110
self.push_transaction_with_compression(tx, with_compression);
111111
let result = self.inspect_inner(tracer, VmExecutionMode::OneTx);
112112
if self.has_unpublished_bytecodes() {
@@ -116,7 +116,10 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
116116
)
117117
} else {
118118
(
119-
Ok(self.bootloader_state.get_last_tx_compressed_bytecodes()),
119+
Ok(self
120+
.bootloader_state
121+
.get_last_tx_compressed_bytecodes()
122+
.into()),
120123
result,
121124
)
122125
}

core/lib/multivm/src/versions/vm_fast/bootloader_state/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ impl BootloaderState {
189189
l2_block.first_tx_index + l2_block.txs.len()
190190
}
191191

192-
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> Vec<CompressedBytecodeInfo> {
192+
pub(crate) fn get_last_tx_compressed_bytecodes(&self) -> &[CompressedBytecodeInfo] {
193193
if let Some(tx) = self.last_l2_block().txs.last() {
194-
tx.compressed_bytecodes.clone()
194+
&tx.compressed_bytecodes
195195
} else {
196-
vec![]
196+
&[]
197197
}
198198
}
199199

0 commit comments

Comments
 (0)