From c8dec5a1400d203f9dd5aa91876f0dca24a7e1db Mon Sep 17 00:00:00 2001 From: Cody Wyatt Neiman Date: Fri, 13 Mar 2026 20:02:02 -0400 Subject: [PATCH 1/2] perf(ans): replace unconditional state normalization w/ explicit branch --- jxl/src/entropy_coding/ans.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jxl/src/entropy_coding/ans.rs b/jxl/src/entropy_coding/ans.rs index 9da5cbee0..868f82931 100644 --- a/jxl/src/entropy_coding/ans.rs +++ b/jxl/src/entropy_coding/ans.rs @@ -384,11 +384,15 @@ impl AnsHistogram { let symbol = (alias_symbol * map_to_alias) | (i as u32 * (1 - map_to_alias)); let offset = offset + pos; - let next_state = (*state >> LOG_SUM_PROBS) * dist + offset; - let select_appended = (next_state < (1 << 16)) as u32; - let appended_state = (next_state << 16) | (br.peek(16) as u32); - *state = (appended_state * select_appended) | (next_state * (1 - select_appended)); - br.consume_optimistic((16 * select_appended) as usize); + let mut next_state = (*state >> LOG_SUM_PROBS) * dist + offset; + + // Use an explicit branch to bypass the BitReader's internal + // bounds-checks when state normalization isn't required. + if next_state < (1 << 16) { + next_state = (next_state << 16) | (br.read_optimistic(16) as u32); + } + *state = next_state; + symbol } From 0d7fe8dd044cd1e07c6c66283887bb9429c7058b Mon Sep 17 00:00:00 2001 From: Cody Wyatt Neiman Date: Fri, 13 Mar 2026 20:39:28 -0400 Subject: [PATCH 2/2] chore(authors): add Cody Neiman --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index ac9e23b1b..c72030a5b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -33,3 +33,4 @@ Tomáš Král Wonwoo Choi Zoltan Szabadka Mert Alev <101130780+mertalev@users.noreply.github.com> +Cody Neiman