Skip to content

Optimize performance of LowPassFilter#86

Merged
hecomi merged 1 commit intohecomi:mainfrom
mrxz:low-pass-filter-perf
Jan 6, 2026
Merged

Optimize performance of LowPassFilter#86
hecomi merged 1 commit intohecomi:mainfrom
mrxz:low-pass-filter-perf

Conversation

@mrxz
Copy link
Contributor

@mrxz mrxz commented Jan 23, 2025

While profiling my wasm port wLipSync, I noticed that the low pass filter was the most expensive by a large margin. Luckily, the performance can be improved drastically with some minor changes. After testing if these performance gains are also possible in uLipSync with the Burst compiler, I can confirm that they are! :-)

This PR optimizes the LowPassFilter function by swapping the inner and outer loop and eliminating the if statement. The following table shows the performance improvement when measuring the entire algorithm (rough measurements):

ms/it
base 3.22 ms
swapping inner and outer loops 1.48 ms
eliminating if statement 0.82 ms

There is one further optimization possible. Since the next step will be downsampling, the low pass filter can be applied only to the samples that are a multiple of skip in case of DownSampleExact, as the other samples are ignored anyway. But this requires more work to get the skip value used in DownSample before calling LowPassFilter. For reference, here's the commit implementing it: mrxz/wLipSync@5ded0c4

@hecomi
Copy link
Owner

hecomi commented Feb 9, 2025

Thank you for the excellent PR! I'll review it as soon as possible and get it merged.

@hecomi hecomi merged commit 96955f9 into hecomi:main Jan 6, 2026
@hecomi
Copy link
Owner

hecomi commented Jan 6, 2026

Sorry for the very late review, and thank you so much for the excellent pull request!

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