From 2baca5a6872e22e959ab60b7c27d48a29a02909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 17:08:58 +0300 Subject: [PATCH] perf(av1): snapshot the remaining per-pixel EC_* env reads `restoration.rs`'s three `EC_LR_CALL_DUMP` guards sit inside the sgrproj per-pixel loops (`compute_ab`, the combine tap) and `warp.rs`'s `EC_MC_TRACE` on the per-MC-call warp entry; each was a live `getenv` + `strlen` + `CStr` validation, 17.75% of `decode_probe`'s self time at 4K. Same predicates, served by `envflags::env_flag!` (one `LazyLock` per call site). `motion_field.rs`'s two `EC_TRACE_TPL` reads move with them. `tile.rs`'s two sites stay: :34 already caches into an atomic and :3002 is test-only. Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 55.31 s -> 48.53 s (interleaved medians of 3), 1080p 10.54 s -> 9.83 s. --- crates/ec-av1/src/motion_field.rs | 4 ++-- crates/ec-av1/src/restoration.rs | 6 +++--- crates/ec-av1/src/warp.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/motion_field.rs b/crates/ec-av1/src/motion_field.rs index 5768e499..d83bc3dd 100644 --- a/crates/ec-av1/src/motion_field.rs +++ b/crates/ec-av1/src/motion_field.rs @@ -461,7 +461,7 @@ pub fn setup_motion_field( ); } - if std::env::var_os("EC_TRACE_TPL").is_some() { + if crate::envflags::env_flag!("EC_TRACE_TPL") { eprintln!("EC_TPL_FIELD oh={cur_order_hint} rows={rows} cols={cols}"); for r in 0..rows { let row: String = (0..cols) @@ -516,7 +516,7 @@ pub fn add_tpl_ref_mv( return None; } let probe = tpl.get(row8 as usize / 2, col8 as usize / 2); - if std::env::var_os("EC_TRACE_TPL").is_some() { + if crate::envflags::env_flag!("EC_TRACE_TPL") { match probe { None => eprintln!("EC_TPL mi_row={mi_row} mi_col={mi_col} blk=({blk_row},{blk_col}) INVALID"), Some((m, rfo)) => eprintln!( diff --git a/crates/ec-av1/src/restoration.rs b/crates/ec-av1/src/restoration.rs index f159dad0..3a37bd71 100644 --- a/crates/ec-av1/src/restoration.rs +++ b/crates/ec-av1/src/restoration.rs @@ -705,7 +705,7 @@ fn compute_ab( (256 - a_val) as i64 * b * SGR_ONE_BY_X[(n - 1) as usize] as i64, SGRPROJ_RECIP_BITS, ); - if std::env::var("EC_LR_CALL_DUMP").is_ok() + if crate::envflags::env_flag!("EC_LR_CALL_DUMP") && v_start as i64 + i == 60 && h_start as i64 + j == 6 && r == 1 @@ -759,7 +759,7 @@ fn apply_sgrproj_stripe( // r7 traced (`[-16,-32]`); dump the real 9-byte dense-arm (r1) "u"-tap // window (physical rows 59..=61, cols 5..=7 -- r7's traced tap) straight // from `lr_sample` for this exact call, no coordinate matching involved. - if std::env::var("EC_LR_CALL_DUMP").is_ok() && r1 > 0 && info.xqd == [-16, -32] { + if crate::envflags::env_flag!("EC_LR_CALL_DUMP") && r1 > 0 && info.xqd == [-16, -32] { let bytes: Vec = (59..=61) .flat_map(|row| { (5..=7).map(move |col| { @@ -844,7 +844,7 @@ fn apply_sgrproj_stripe( let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3; let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS); v += xq[1] as i64 * (flt1 - u); - if std::env::var("EC_LR_CALL_DUMP").is_ok() + if crate::envflags::env_flag!("EC_LR_CALL_DUMP") && info.xqd == [-16, -32] && v_start as i64 + i == 61 && h_start as i64 + j == 6 diff --git a/crates/ec-av1/src/warp.rs b/crates/ec-av1/src/warp.rs index 24a8a771..1ec27312 100644 --- a/crates/ec-av1/src/warp.rs +++ b/crates/ec-av1/src/warp.rs @@ -444,7 +444,7 @@ pub fn warp_affine( subsampling_x: i32, subsampling_y: i32, ) { - if std::env::var_os("EC_MC_TRACE").is_some() { + if crate::envflags::env_flag!("EC_MC_TRACE") { eprintln!("EC_MC_WARP x={p_col} y={p_row} w={p_width} h={p_height}"); } let bd = i32::from(crate::decode::bit_depth());