Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize performance of LowPassFilter #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrxz
Copy link

@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.

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