Skip to content

Commit

Permalink
perf: writing tx to memory is no longer quadratic
Browse files Browse the repository at this point in the history
It used to grow proportionally to the number of transactions squared.
  • Loading branch information
joonazan committed Jul 24, 2024
1 parent 616e324 commit bbe33bc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions core/lib/multivm/src/versions/vm_fast/bootloader_state/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ pub(super) fn apply_tx_to_memory(
(tx_description_offset..tx_description_offset + bootloader_tx.encoded_len())
.zip(bootloader_tx.encoded.clone()),
);

let bootloader_l2_block = if start_new_l2_block {
bootloader_l2_block.clone()
} else {
bootloader_l2_block.interim_version()
};
apply_l2_block(memory, &bootloader_l2_block, tx_index);
apply_l2_block_inner(memory, bootloader_l2_block, tx_index, start_new_l2_block);

// Note, +1 is moving for pointer
let compressed_bytecodes_offset = COMPRESSED_BYTECODES_OFFSET + 1 + compressed_bytecodes_size;
Expand All @@ -90,6 +84,15 @@ pub(crate) fn apply_l2_block(
memory: &mut BootloaderMemory,
bootloader_l2_block: &BootloaderL2Block,
txs_index: usize,
) {
apply_l2_block_inner(memory, bootloader_l2_block, txs_index, true)
}

fn apply_l2_block_inner(
memory: &mut BootloaderMemory,
bootloader_l2_block: &BootloaderL2Block,
txs_index: usize,
start_new_l2_block: bool,
) {
// Since L2 block information start from the `TX_OPERATOR_L2_BLOCK_INFO_OFFSET` and each
// L2 block info takes `TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO` slots, the position where the L2 block info
Expand All @@ -107,7 +110,12 @@ pub(crate) fn apply_l2_block(
),
(
block_position + 3,
bootloader_l2_block.max_virtual_blocks_to_create.into(),
if start_new_l2_block {
bootloader_l2_block.max_virtual_blocks_to_create
} else {
0
}
.into(),
),
])
}
Expand Down

0 comments on commit bbe33bc

Please sign in to comment.