Skip to content

Commit 9c826a6

Browse files
print cairo_runner and prover_input size.
1 parent c24e1a8 commit 9c826a6

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.github/workflows/upload_artifacts_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Upload-Artifacts
33
on:
44
push:
55
branches:
6-
- main
6+
- or/print_cairo_runner_prover_input_size
77

88
jobs:
99
artifacts-push:

crates/cairo-program-runner-lib/src/hints/load_cairo_pie.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ fn relocate_cairo_pie_memory(
294294

295295
vm.insert_value(relocated_address, relocated_value)?;
296296
}
297+
tracing::info!("cairo pie memory relocated memory: {} bytes", std::mem::size_of_val(&vm.segments.memory));
297298
Ok(())
298299
}
299300

crates/vm_runner/src/main.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ enum Error {
6262
Anyhow(#[from] anyhow::Error),
6363
}
6464

65+
/// Calculate approximate heap memory usage for a Vec
66+
fn vec_heap_size<T>(vec: &Vec<T>) -> usize {
67+
vec.capacity() * std::mem::size_of::<T>()
68+
}
69+
70+
/// Calculate approximate heap memory usage for an Option<Vec<T>>
71+
fn option_vec_heap_size<T>(opt_vec: &Option<Vec<T>>) -> usize {
72+
opt_vec.as_ref().map(|v| vec_heap_size(v)).unwrap_or(0)
73+
}
74+
6575
fn main() -> ExitCode {
6676
run_binary(run, "stwo_vm_runner")
6777
}
@@ -91,8 +101,33 @@ fn run() -> Result<ProverInput, Error> {
91101
};
92102

93103
let cairo_runner = cairo_run_program(&program, program_input_contents, cairo_run_config)?;
104+
105+
// Log stack sizes (struct sizes).
106+
log::info!("=== Stack Sizes (struct metadata only) ===");
107+
log::info!("cairo_runner stack: {} bytes", std::mem::size_of_val(&cairo_runner));
108+
log::info!("cairo_runner.vm stack: {} bytes", std::mem::size_of_val(&cairo_runner.vm));
109+
log::info!("cairo_runner.get_program() stack: {} bytes", std::mem::size_of_val(cairo_runner.get_program()));
110+
log::info!("cairo_runner.exec_scopes stack: {} bytes", std::mem::size_of_val(&cairo_runner.exec_scopes));
111+
log::info!("cairo_runner.relocated_trace stack: {} bytes", std::mem::size_of_val(&cairo_runner.relocated_trace));
112+
113+
// Log heap sizes (actual allocated data).
114+
log::info!("=== Heap Sizes (actual memory consumption) ===");
115+
log::info!("cairo_runner.relocated_trace heap: {} bytes ({} MB)",
116+
option_vec_heap_size(&cairo_runner.relocated_trace),
117+
option_vec_heap_size(&cairo_runner.relocated_trace) / 1_048_576);
118+
119+
// VM segments memory is complex, log the HashMap size.
120+
log::info!("cairo_runner.vm.segments.public_memory_offsets entries: {}",
121+
cairo_runner.vm.segments.public_memory_offsets.len());
122+
94123
let prover_input = adapt(&cairo_runner)?;
95124

125+
log::info!("=== After Adaptation ===");
126+
log::info!("prover_input stack: {} bytes", std::mem::size_of_val(&prover_input));
127+
log::info!("prover_input.public_memory_addresses heap: {} bytes ({} MB)",
128+
vec_heap_size(&prover_input.public_memory_addresses),
129+
vec_heap_size(&prover_input.public_memory_addresses) / 1_048_576);
130+
96131
if let Some(prover_input_path) = args.output_prover_input_path {
97132
std::fs::write(prover_input_path, serde_json::to_string(&prover_input)?)?;
98133
}

0 commit comments

Comments
 (0)