Skip to content

Remove bounds checks from filter_signal - #10

Open
valadaptive wants to merge 1 commit into
dstrub18:mainfrom
valadaptive:opt
Open

valadaptive wants to merge 1 commit into
dstrub18:mainfrom
valadaptive:opt

Conversation

@valadaptive

Copy link
Copy Markdown

The gammatone filterbank is the hottest function in this code by far.

I noticed that the filter_signal function seemed to contain a lot of bounds checks, one per coefficient. Because bounds checks are control flow, they can prevent many useful optimizations.

By passing numerator_coeffs, denom_coeffs, and init_conditions as references to fixed-size arrays rather than slices, the compiler knows all our accesses are inbounds, and can omit the bounds checks.

This allows the code to be vectorized, and is 30-40% faster on my benchmarks.

Performance can probably be improved a lot further with some heavier reworks, but this is a small change that's easy to review.

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.

1 participant