Title: Optimize reverb buffer locality by Ali-Z0 · Pull Request #90 · sezero/mikmod · GitHub
Open Graph Title: Optimize reverb buffer locality by Ali-Z0 · Pull Request #90 · sezero/mikmod
X Title: Optimize reverb buffer locality by Ali-Z0 · Pull Request #90 · sezero/mikmod
Description: Summary Hi MikMod maintainers, My collaborator @thomasstaheli and I recently studied a MikMod-based audio pipeline as part of our High-Performance Computing course at HEIG-VD in Yverdon, Switzerland. During this work, we profiled the reverb mixing code and identified MixReverb_Stereo as a noticeable hotspot in the audio path. This pull request proposes two small optimizations for the reverb mixer: improving the memory layout of the reverb buffers; reducing the arithmetic cost of circular buffer indexing. The goal is to improve performance in a frequently executed DSP path without changing the reverb algorithm or the intended audio output. Motivation The stereo reverb mixer repeatedly accesses 16 circular buffers: RVbufL1 to RVbufL8 for the left channel; RVbufR1 to RVbufR8 for the right channel. In the original implementation, these buffers are allocated separately. This can scatter them across the heap and reduce spatial locality. Since the reverb loop reads and writes these buffers very frequently, a more cache-friendly layout can help reduce memory stalls. The inner loop also performs repeated modulo operations for circular indexing. These modulo operations may compile to integer divisions, which are relatively expensive compared to simple increments and comparisons. Changes 1. Contiguous reverb buffer allocation The separate reverb buffer allocations are replaced with a single contiguous allocation. The existing RVbufL* and RVbufR* pointers are then assigned linearly inside this block. This keeps the rest of the code structure mostly unchanged, while improving spatial locality and reducing heap fragmentation. 2. Strength reduction for circular indexing The repeated modulo-based index updates in the inner reverb loop are replaced with conditional increments: if (++loc >= RVc) loc = 0; The modulo is only needed for initialization. During the loop, the index advances with cheaper operations: increment, comparison, and conditional reset. Performance notes This change was motivated by profiling in a downstream project using MikMod-based audio mixing. In that environment, MixReverb_Stereo was one of the relevant audio hotspots. Using Linux perf, we observed the following self CPU cost for the targeted function: baseline run 1: 5.38%; baseline run 2: 5.69%; optimized run: 4.33%. Using the average of the two baseline runs, this corresponds to a relative reduction of approximately 21.8% for MixReverb_Stereo in that workload. These numbers are workload- and platform-dependent, so they should be interpreted as an indication rather than a universal benchmark. The main goal of this PR is to make the reverb buffer access pattern more cache-friendly and reduce unnecessary arithmetic in a hot loop. Compatibility The reverb algorithm is not intentionally changed. The existing buffer pointer interface is preserved, and the optimization only changes how the buffers are allocated and how circular indices are advanced internally. Please let us know if you would prefer the patch to be split differently, rebased, or adjusted to better match the coding style of the project. Best regards, @Ali-Z0 and @thomasstaheli
Open Graph Description: Summary Hi MikMod maintainers, My collaborator @thomasstaheli and I recently studied a MikMod-based audio pipeline as part of our High-Performance Computing course at HEIG-VD in Yverdon, Switzerlan...
X Description: Summary Hi MikMod maintainers, My collaborator @thomasstaheli and I recently studied a MikMod-based audio pipeline as part of our High-Performance Computing course at HEIG-VD in Yverdon, Switzerlan...
Opengraph URL: https://github.com/sezero/mikmod/pull/90
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/commits/:range(.:format) |
| route-controller | pull_requests |
| route-action | commits |
| fetch-nonce | v2:3f7db2d2-c94f-efda-d749-4a1a694961cc |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9638:3C53BD:4DDCE8B:67B798E:6A655CAC |
| html-safe-nonce | 9ea2635b1295b197ac84256dfc65bca268e301ec27530d56bd0510aa4dd592af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjM4OjNDNTNCRDo0RERDRThCOjY3Qjc5OEU6NkE2NTVDQUMiLCJ2aXNpdG9yX2lkIjoiNTExODYwMDc1NTA5MzUyNzcyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 82e111fb79d08412e646ff10374ccd15bbdf1c9da9dd577a9e1a48532d26b3d1 |
| hovercard-subject-tag | pull_request:3822799301 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/sezero/mikmod/pull/90/commits/23ee402a1f6544a1aa66307c13cfb7e67ba2bc60 |
| twitter:image | https://avatars.githubusercontent.com/u/107996590?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/107996590?s=400&v=4 |
| og:image:alt | Summary Hi MikMod maintainers, My collaborator @thomasstaheli and I recently studied a MikMod-based audio pipeline as part of our High-Performance Computing course at HEIG-VD in Yverdon, Switzerlan... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c76df668885aaff23b50bdca1fa1ea44ac9c1553e888ebc70ff1e4daa4625b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/sezero/mikmod git https://github.com/sezero/mikmod.git |
| octolytics-dimension-user_id | 4222725 |
| octolytics-dimension-user_login | sezero |
| octolytics-dimension-repository_id | 114225902 |
| octolytics-dimension-repository_nwo | sezero/mikmod |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 114225902 |
| octolytics-dimension-repository_network_root_nwo | sezero/mikmod |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 309153364422b3c499922d1a2a6404910a58ed8e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width