From 85f472d824cb2f4e3aa9ab42004e883ef5762a05 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Fri, 27 Mar 2026 14:21:21 +0400 Subject: [PATCH] fix: scale FEC ratio with loss rate in benchmarks The bench tool now auto-calculates the FEC ratio needed to survive the requested loss percentage, matching how the adaptive quality controller would behave in production. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wzp-client/src/bench.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/wzp-client/src/bench.rs b/crates/wzp-client/src/bench.rs index 3eb7e42..dbde097 100644 --- a/crates/wzp-client/src/bench.rs +++ b/crates/wzp-client/src/bench.rs @@ -136,8 +136,13 @@ pub fn bench_fec_recovery(loss_pct: f32) -> FecResult { let profile = QualityProfile::GOOD; // 5 frames/block, 0.2 ratio let frames_per_block = profile.frames_per_block as usize; let num_blocks = 100; - // Use a higher FEC ratio for the bench so recovery is possible at higher loss - let fec_ratio = if loss_pct > 20.0 { 1.0 } else { 0.5 }; + // Scale FEC ratio to survive the requested loss rate. + // At X% loss, we keep (1-X/100) of packets. We need at least + // frames_per_block packets to recover, so total packets needed = + // frames_per_block / (1 - loss/100). Ratio = (total - source) / source. + let keep_fraction = 1.0 - (loss_pct / 100.0).min(0.95); + let total_needed = (frames_per_block as f32 / keep_fraction).ceil(); + let fec_ratio = ((total_needed / frames_per_block as f32) - 1.0).max(0.2); let start = Instant::now();