use crate::perf_lock;
use spg_engine::Engine;
const ROWS: usize = 2_000;
const BODY_BYTES: usize = 4 * 1024; const K_CEILING: u64 = 4;
#[test]
fn resident_footprint_is_a_bounded_multiple_of_data() {
let _g = perf_lock();
let mut eng = Engine::new();
eng.execute("CREATE TABLE t (id BIGINT, body TEXT)")
.unwrap();
let mut raw_bytes: u64 = 0;
let mut i = 0usize;
while i < ROWS {
let mut stmt = String::with_capacity(50 * BODY_BYTES);
stmt.push_str("INSERT INTO t VALUES ");
for k in 0..50 {
let id = i + k + 1;
if k > 0 {
stmt.push(',');
}
let body = format!("{id:08}{}", "x".repeat(BODY_BYTES - 8));
raw_bytes += 8 + body.len() as u64; stmt.push_str(&format!("({id},'{body}')"));
}
eng.execute(&stmt).unwrap();
i += 50;
}
let stats = eng.memory_stats();
let resident = stats.total_approx_resident_bytes;
let k = resident as f64 / raw_bytes as f64;
println!("RESIDENT raw={raw_bytes} resident={resident} k={k:.2}");
assert!(
resident <= raw_bytes * K_CEILING,
"resident {resident} bytes is {k:.1}x the {raw_bytes} bytes of data \
(ceiling {K_CEILING}x) — the representation amplification regressed \
toward the R30 11x blow-up"
);
}