Skip to content

Optimize render-loop output path#2

Open
Solvely-Colin wants to merge 1 commit into
mainfrom
solvely-colin/performance-improvements-2
Open

Optimize render-loop output path#2
Solvely-Colin wants to merge 1 commit into
mainfrom
solvely-colin/performance-improvements-2

Conversation

@Solvely-Colin

Copy link
Copy Markdown
Owner

Summary

  • optimize hot-path allocations in RenderLoopProcessor.floatBuffers by reserving capacity and using known sample counts
  • avoid extra map+reduce allocation in outputSnapshot by computing capacities and total in one pass
  • reduce per-sample overhead in multi-buffer writes by replacing repeated bounds checks with integer comparisons and early termination
  • switch single-buffer writes to memcpy for contiguous copy

Why this change

This is a high-impact, low-effort improvement because it targets the Core Audio callback path (AudioRenderLoop) where even small per-callback savings compound quickly under sustained playback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 10, 2026 13:03

Copilot AI left a comment

Copy link
Copy Markdown

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 optimizes the Core Audio callback hot path in RenderLoopProcessor by reducing allocations and per-sample overhead during input snapshotting and output writes.

Changes:

  • Pre-reserve capacities when building input/output snapshots to reduce allocations.
  • Replace map + reduce with a single-pass capacity calculation in outputSnapshot.
  • Speed up output writes by caching counts, using early termination, and switching single-buffer writes to memcpy.

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

Comment on lines +714 to 719
} else if sampleIndex < mixedSampleCount {
outputSamples[sampleIndex] = mixedSamples[sampleIndex]
writtenSampleCount += 1
} else {
break
}
Comment on lines +738 to +743
samples.withUnsafeBufferPointer { sourceBuffer in
memcpy(
outputSamples,
sourceBuffer.baseAddress,
writtenSampleCount * MemoryLayout<Float>.stride
)
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