Skip to content

huff2/quantize: optimize scale-factor and codebook processing - #183

Merged
fabiangreffrath merged 1 commit into
knik0:masterfrom
nschimme:go-faster
Aug 30, 2026
Merged

huff2/quantize: optimize scale-factor and codebook processing#183
fabiangreffrath merged 1 commit into
knik0:masterfrom
nschimme:go-faster

Conversation

@nschimme

Copy link
Copy Markdown
Contributor

Performance optimization: Accelerates libfaac encoding by +2.7% to +4.0% by eliminating redundant array passes, replacing expensive transcendental math (powf, sqrtf, log10f) with LUTs, and unrolling hot loops—with 100% bit-exact output.

Key Changes

  • Single-Pass Maxima Tracking: quantize_scalar() and quantize_sse2() now return maxq, removing a redundant spectral scanning pass in huffbook().
  • Precomputed LUTs: Added gain_lut (512 entries for quarter-dB steps) and log10_width_sf_lut (128 entries) to replace powf() calls in gain coupling.
  • Math Simplification: Reused sf_enrg_avg via log identities to remove duplicate division and sqrtf() operations in assign_band_codebooks().
  • Encoding Loops & Annotations: Unrolled tuple loops and simplified sign checks in huff2.c; added const and __restrict annotations to hot paths.

Benchmarks & Impact

  • Encoding Speed: +2.7% to +4.0% overall throughput speedup across test scenarios.
  • Correctness: 100% bit-exact MOS quality verified across 1,339 audio test clips.
  • Binary Footprint: -264 bytes text segment in libfaac.so (-0.44%).
  • https://github.com/nschimme/faac/actions/runs/33286483326

Accelerate AAC quantization and Huffman codebook selection by avoiding
redundant array scans and replacing runtime math with lookup tables.

- Track band maxima during quantization to avoid rescanning in huffbook()
- Precompute gain and band-width lookup tables to replace powf/log10f calls
- Reuse energy metrics in sfac allocation to eliminate div/sqrtf operations
- Streamline loop iterations and sign checks in Huffman encoding paths
- Add const and restrict annotations for better compiler optimizations

Impact:
- +2.7% to +4.0% overall encoding speedup
- -264 bytes text footprint in libfaac.so (-0.44%)
@fabiangreffrath
fabiangreffrath merged commit 3da4bdf into knik0:master Aug 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants