ESP/Speaker: Avoid repeated heap allocations in `TAS5805::play()`
- Dominant language
- Go
- Stars
- 0
- Forks
- 0
- Avg merge
- 1h 27m
- Merged PRs (30d)
- 1
Description
## Problem
`TAS5805::play()` allocates several large buffers each time it is called:
- approximately 32 KB DMA/staging buffer
- up to approximately 16 KB file buffer
- approximately 16 KB stereo I2S buffer
These buffers are then freed before `play()` returns.
Because `audio_task()` repeatedly calls `play()`, playback repeatedly allocates and frees large heap blocks. On a device that also performs networking, HTTP, TLS, and other dynamic allocations, this creates unnecessary heap churn and may contribute to long-term heap fragmentation.
The issue is not simply the total amount of allocated memory; repeatedly requesting and freeing large blocks can reduce the size of the largest contiguous free region over time.
## Proposed change
Allocate the playback buffers once and reuse them across playback passes.
Suitable approaches include:
- allocating them during TAS5805/audio initialization and retaining them for the lifetime of the player, or
- lazily allocating them on the first playback pass and reusing them thereafter.
The I2S buffer must continue to satisfy any memory/DMA requirements imposed by the I2S driver.
Release the buffers only when playback resources are explicitly torn down, such as during an appropriate shutdown/reinitialization path.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating TAS5805::play() and the audio_task() call path, then trace how playback and audio resources are initialized and torn down. Confirm that the DMA/staging, file, and stereo I2S buffers are reused across playback passes, still meet I2S memory requirements, and are released during explicit resource teardown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- embedded-iot, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100