use ifc_model::Codec;
const PER_WALL: usize = 10;
mod common;
use common::synthesize;
fn peak_rss_kb() -> Option<u64> {
let status = std::fs::read_to_string("/proc/self/status").ok()?;
status
.lines()
.find(|l| l.starts_with("VmHWM:"))?
.split_whitespace()
.nth(1)?
.parse()
.ok()
}
#[test]
fn parsing_a_large_model_stays_within_its_memory_budget() {
let Some(_) = peak_rss_kb() else {
eprintln!("skipped: /proc/self/status unavailable");
return;
};
let walls = 60_000;
let text = synthesize(walls);
let bytes = text.len() as f64;
let before = peak_rss_kb().unwrap();
let model = ifc_step::StepCodec
.read_bytes(text.as_bytes())
.expect("synthetic model parses");
let after = peak_rss_kb().unwrap();
let expected = walls * PER_WALL + 8;
assert_eq!(model.ids().count(), expected, "entity count");
let growth_kb = after.saturating_sub(before) as f64;
let ratio = (growth_kb * 1024.0) / bytes;
assert!(
ratio < 10.0,
"parse used {ratio:.1}x the input size in RSS ({growth_kb:.0} KB for {bytes:.0} bytes); \
budget is 10x -- a new per-entity allocation or a retained source copy is the usual cause"
);
eprintln!(
"scale: {walls} walls, {:.0} MB input, {ratio:.1}x RSS",
bytes / 1048576.0
);
}