Skip to content

Fix bad code generation on wasm simd butterflies - #185

Merged
ejmahler merged 3 commits into
masterfrom
fix-failed-inlining
Sep 26, 2026
Merged

ejmahler merged 3 commits into
masterfrom
fix-failed-inlining

Conversation

@ejmahler

@ejmahler ejmahler commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

While benchmarking a new simd radix4, I noticed very bad performance regressions on wasm. After investigating, I found that the butterflies were being generated with fallback functions for all the simd instrinsics.

I narrowed it down to our "wasm simd fft helper" functions: They take lambdas to process each chunk of input data, and lambdas inherit the target feature of their owning function. Since they were declared in non-target-feature functions, they didn't have it either. The compiler for Wasm simd seems to heavily pessimize inlining, and lambdas are declared with just #[inline], not #[inline(always)], so we can't force the compiler to inline them. So the final location for the butterfly code was a function that did not have the simd target feature.

So this does the next best thing, it changes paradigms so that the "fft helper" is in the body of the butterfly struct (still in the macro of course), so that the lambdas we declare to process data inherit the target feature. This results in the code being much smaller, so it gets reliably inlined, and it will still be correct even if it isn't inlined.

Finally, wasm simd lets you put the target feature attribute directly on the trait methods, so they don't neven need the seperate helper functions.

@ejmahler
ejmahler merged commit 586c096 into master Sep 26, 2026
21 checks passed
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