dotnet / dotnet/macios

AudioUnit allocates on the heap for every RenderCallback

Open
#8,836 5 comments 0 reactions 0 assignees View on GitHub
api-bindings enhancement performance
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

### Steps to Reproduce

1. Go to https://github.com/xamarin/xamarin-macios/blob/master/src/AudioUnit/AudioUnit.cs
2. Go to line 730 in method RenderCallbackImpl
2. Notice that for every AudioRender callback an AudioBuffers instance is allocated on the heap

### Expected Behavior
No heap allocations during audio playback

### Actual Behavior
A new AudioBuffer is allocated for every call for me this is 50 times a second. This will be slow, and increase the frequency of Garbage collection calls, resulting in GC pauses during playback which could impact audio quality.

### Environment
You can see this by looking at the github code

Possible solutions:
* Provide a way to specify a AudioBuffers instance for it to reuse. (if the user knows this is safe, ie doesn't hold onto it)
* Change AudioBuffers to a struct, so it is allocated on the stack instead.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.