Skip to content

Optimize AV2 encoder by removing redundant memset calls - #5194

Merged
leolzhao merged 6 commits into
AOMediaCodec:av2-encfrom
JimDBh:av2-enc
Aug 6, 2026
Merged

Optimize AV2 encoder by removing redundant memset calls#5194
leolzhao merged 6 commits into
AOMediaCodec:av2-encfrom
JimDBh:av2-enc

Conversation

@JimDBh

@JimDBh JimDBh commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Eliminate redundant memset and buffer-zeroing overhead across quantization and forward transform routines:

  1. Remove unnecessary memset calls in av2_quantize_skip, highbd_quantize_dc, and av2_xform_dc_only where eob is set to 0 or coefficients are directly written.

  2. Remove = { 0 } zero-initialization from the 16 KB stack buffer int buf[MAX_TX_SQUARE]` in fwd_txfm_c and fwd_txfm_avx2, as the buffer is unconditionally overwritten by the column 1D transform before being read.

Anchor:
dd6f21f

Tests: 33 frame CTC against dd6f21f

Speed 1:

| Set | Y | U | V | YUV | Enc-time |
|---------+-------+-------+-------+-------+----------|
| A1 | 0.00% | 0.00% | 0.00% | 0.00% | 97.6% |
| A2 | 0.00% | 0.00% | 0.00% | 0.00% | 96.7% |

Speed 4:
| Set| Y | U | V | YUV | Enc-time |
|---------+-------+-------+-------+-------+----------|
| A1 | 0.00% | 0.00% | 0.00% | 0.00% | 98.0% |
| A2 | 0.00% | 0.00% | 0.00% | 0.00% | 97.3% |

Eliminates unnecessary memset calls in av2_quantize_skip,
highbd_quantize_dc, and av2_xform_dc_only where eob is set to 0 or
coefficients are written directly.

TAG=agy
CONV=dfbcd5f8-b1c1-4b21-904b-b14f69c835cc
Removes "= { 0 };" zero-initialization from the 16 KB stack buffer
"int buf[MAX_TX_SQUARE]" in fwd_txfm_c and fwd_txfm_avx2. The entire
buffer is written by the column 1D transform before being read by the
row 1D transform.

Includes an explicit assertion (assert(width >= 4 && height >= 4)) to
document valid transform dimensions and hint to Clang Static Analyzer
during symbolic execution, preventing false positive uninitialized memory
warnings.

TAG=agy
CONV=dfbcd5f8-b1c1-4b21-904b-b14f69c835cc
Comment thread av2/encoder/x86/highbd_fwd_txfm_avx2.c
Comment thread av2/encoder/av2_quantize.c Outdated
Comment thread av2/encoder/av2_quantize.c Outdated
Comment thread av2/encoder/hybrid_fwd_txfm.c Outdated
- Sort config/ and project header includes alphabetically in
  hybrid_fwd_txfm.c and highbd_fwd_txfm_avx2.c.
- Place system header <assert.h> before project headers in
  hybrid_fwd_txfm.c.
- Clean up av2_quantize_skip signature to void av2_quantize_skip(uint16_t *eob_ptr),
  removing unused n_coeffs, qcoeff_ptr, and dqcoeff_ptr parameters.
- Remove unused n_coeffs parameter from static inline helper
  highbd_quantize_dc.

TAG=agy
CONV=f1b0a382-a1eb-48a9-9834-f89940af07ff

@yeqing-wu yeqing-wu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

@leolzhao
leolzhao merged commit 587f50e into AOMediaCodec:av2-enc Aug 6, 2026
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants