Skip to content

[1/3] Reduce SILK decode allocations#114

Merged
zshang-oai merged 2 commits into
pion:mainfrom
zshang-oai:codex/reduce-silk-decode-allocations
May 20, 2026
Merged

[1/3] Reduce SILK decode allocations#114
zshang-oai merged 2 commits into
pion:mainfrom
zshang-oai:codex/reduce-silk-decode-allocations

Conversation

@zshang-oai
Copy link
Copy Markdown
Contributor

@zshang-oai zshang-oai commented May 18, 2026

Summary

Reduce avoidable allocation churn in the SILK decoder hot path. This is part of a series PRs to get an 2x performance boost with low hanging fruits.

What changed

  • reuse decoder-owned scratch buffers for SILK header flags, pulse/excitation data, LPC working buffers, residual buffers, NLSF/LPC coefficient work, pitch lags, and LTP filter coefficients
  • skip LBRR discard decoding when the packet does not signal any LBRR frames
  • reuse previousFrameLPCValues storage instead of allocating a fresh slice on each handoff
  • replace tiny pulse partition scratch allocations with stack arrays

Why

The SILK decode path was allocating transient slices on nearly every packet. In local stress benchmarks those allocations were a large avoidable part of the Pion/Opus gap.

This PR keeps the decode algorithm unchanged and only removes repeated scratch allocation work.

Validation

go test ./...

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 96.55172% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.56%. Comparing base (de54ba8) to head (906eb7b).

Files with missing lines Patch % Lines
internal/silk/decoder.go 96.55% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #114      +/-   ##
==========================================
- Coverage   82.96%   82.56%   -0.41%     
==========================================
  Files          22       22              
  Lines        4697     4742      +45     
==========================================
+ Hits         3897     3915      +18     
- Misses        609      635      +26     
- Partials      191      192       +1     
Flag Coverage Δ
go 82.56% <96.55%> (-0.41%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces allocation churn in the SILK decoder hot path by reusing decoder-owned scratch buffers and avoiding unnecessary LBRR discard work when no redundancy is signaled.

Changes:

  • Adds reusable scratch storage to Decoder for header flags, pulse/excitation buffers, LPC/NLSF work buffers, pitch/LTP data, and stereo-related decode state.
  • Refactors allocation-heavy helpers to resize and clear decoder-owned buffers instead of allocating fresh slices.
  • Short-circuits LBRR discard decoding when no mid/side LBRR flags are present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zshang-oai zshang-oai changed the title Reduce SILK decode allocations [1/3] Reduce SILK decode allocations May 18, 2026
@zshang-oai zshang-oai requested review from JoTurk and Sean-Der May 18, 2026 23:11
@zshang-oai zshang-oai marked this pull request as ready for review May 18, 2026 23:11
@zshang-oai zshang-oai merged commit f682a5f into pion:main May 20, 2026
19 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.

3 participants