Created
December 12, 2025 17:40
-
-
Save huitseeker/f957014b15b0ed08a36b7f936079b698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Demo to measure padding overhead in basic blocks | |
| use miden_core_lib::CoreLibrary; | |
| use miden_core::{Operation, mast::MastNode}; | |
| fn main() { | |
| let libcore = CoreLibrary::default(); | |
| let mast_forest = libcore.mast_forest(); | |
| let total_nodes = mast_forest.num_nodes(); | |
| let mut basic_block_count = 0; | |
| let mut total_operations = 0; | |
| let mut total_noop_padding = 0; | |
| let mut total_batches = 0; | |
| for node_idx in 0..total_nodes { | |
| let node_id = miden_core::mast::MastNodeId::from_u32_safe(node_idx as u32, mast_forest.as_ref()).unwrap(); | |
| if let MastNode::Block(basic_block) = &mast_forest[node_id] { | |
| basic_block_count += 1; | |
| let operations: Vec<Operation> = basic_block.operations().copied().collect(); | |
| let num_ops = operations.len(); | |
| total_operations += num_ops; | |
| // Count NOOPs (assuming NOOP is the padding operation) | |
| let num_noops = operations.iter().filter(|op| matches!(op, Operation::Noop)).count(); | |
| total_noop_padding += num_noops; | |
| let op_batches = basic_block.op_batches(); | |
| let num_batches = op_batches.len(); | |
| total_batches += num_batches; | |
| } | |
| } | |
| println!("=== Padding Overhead Analysis ==="); | |
| println!("Total nodes: {}", total_nodes); | |
| println!("Basic block nodes: {}", basic_block_count); | |
| println!("Total operations (with padding): {}", total_operations); | |
| println!("Total NOOP padding operations: {}", total_noop_padding); | |
| println!("Non-padding operations: {}", total_operations - total_noop_padding); | |
| println!("Padding ratio: {:.2}%", (total_noop_padding as f64 / total_operations as f64) * 100.0); | |
| println!(); | |
| println!("Total batches: {}", total_batches); | |
| println!("Average batches per basic block: {:.2}", total_batches as f64 / basic_block_count as f64); | |
| println!(); | |
| // Calculate metadata overhead | |
| let batch_metadata_size = total_batches * 10; // 10 bytes per batch | |
| let batch_count_overhead = basic_block_count * 4; // 4 bytes per basic block for batch count | |
| let total_metadata_overhead = batch_metadata_size + batch_count_overhead; | |
| println!("=== Metadata Overhead ==="); | |
| println!("Batch metadata: {} bytes ({} batches × 10 bytes)", batch_metadata_size, total_batches); | |
| println!("Batch count fields: {} bytes ({} blocks × 4 bytes)", batch_count_overhead, basic_block_count); | |
| println!("Total metadata overhead: {} bytes ({:.2} KB)", total_metadata_overhead, total_metadata_overhead as f64 / 1024.0); | |
| println!("Metadata per basic block: {:.2} bytes", total_metadata_overhead as f64 / basic_block_count as f64); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment