test: measure incremental stream render cost as a message grows

A probe rather than a gate: it reports the cost of the production render path
(parse + render_parsed) while a markdown document grows one word at a time, which
is what the transcript does during a stream. There is no assertion because a
wall-clock budget in a test would flake on a shared machine, and the repository
has no performance gate to put it in yet (#6193); the value here is that the
number is reproducible instead of remembered.

Measured (debug build; the slope is the finding, not the absolute):

    bytes=1171   per_append=144µs
    bytes=4688   per_append=826µs
    bytes=9375   per_append=1.76ms

Cost per append grows roughly linearly with document size, so streaming one
message costs about quadratically overall. Filed as #6196.
This commit is contained in:
CodeWhale Bot committed 2026-09-15 00:41:28 -07:00
1 parent 230911badd
commit 87c8f583d9
1 file changed
+32
+32
View File
@@ -3962,4 +3962,36 @@ mod tests {
);
}
}
#[test]
fn probe_incremental_stream_cost() {
// Faithful to one streaming message: the document grows a word at a
// time and the render path re-parses and re-renders the whole visible
// text on every tick. Reports the cost per 250 appends so growth with
// message size is visible.
use std::time::Instant;
let words: Vec<&str> = "the quick brown fox jumps over a lazy dog and then keeps going for a while"
.split(' ')
.collect();
let mut doc = String::new();
let width = 100u16;
let mut window_start = Instant::now();
for i in 0..2000usize {
doc.push_str(words[i % words.len()]);
doc.push(' ');
let parsed = parse(&doc);
let lines = render_parsed(&parsed, width, Style::default());
std::hint::black_box(&lines);
if (i + 1) % 250 == 0 {
let elapsed = window_start.elapsed();
println!(
"PROBE bytes={} per_append={:?} total={:?}",
doc.len(),
elapsed / 250,
elapsed
);
window_start = Instant::now();
}
}
}
}