Skip to content

PoC: 6% clean build time improvement by using trait defaults - #445

Draft
Shnatsel wants to merge 3 commits into
linebender:mainfrom
Shnatsel:clean-build-time-improvements
Draft

Shnatsel wants to merge 3 commits into
linebender:mainfrom
Shnatsel:clean-build-time-improvements

Conversation

@Shnatsel

@Shnatsel Shnatsel commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Use trait defaults and override them where necessary instead of re-emitting the same implementation over and over.

On x86 this reduces the build time by 6% in the default configuration in both debug and release modes, measured on a hello world crate that depends on fearless_simd and nothing else, but doesn't actually use any of the functions. The total LoC count is reduced by 11%.

This isn't meant to be merged as is. It is a proof of concept to see if this direction is worth pursuing. This was mostly an exercise to take DeepSeek v4.1 Flash for a spin and see how it performs at agentic work. I haven't reviewed this in depth, and might never get around to reviewing this. This whole exercise plus generated assembly verification and fixing the issues it uncovered in the initial pass cost me $0.44 at official API rates.

This also needs to be measured on Vello benchmarks before landing because some runtime performance regressions might not show up on isolated testcases.

Introduce trait_default_op and the per-backend overrides_trait_default hook
so the generator can emit derived operations once in the Simd trait instead
of in every backend. This commit only adds the plumbing; generated output is
unchanged.
Move operations that can be expressed in terms of other Simd methods out of
every backend impl and into shared trait defaults: mask rotation, reversal,
selection and bitwise ops, mask/integer conversions, byte-routed and/or/xor,
compression/expansion, interleave/deinterleave, widening arithmetic, pairwise
dot products, classification, clamp, count_zeros and 8-bit swap_bytes.

Backends keep native implementations through overrides_trait_default where
that is faster: AVX-512 mask/compact/classify paths, SSE2 count_zeros, native
x86 select/neg/interleave/deinterleave, x86 widening, and Neon/Wasm native ops.
Operations whose wide-vector split/combine default is already better stay on
that path above 128 bits.

Generated source shrinks by about 14.1k lines.
Move the common slice accessors, slice conversion helpers and splat body
from every vector and mask impl into defaults on SimdBase and SimdMask.
This removes four methods from each of the generated vector impls and two
from each mask impl. The Array associated type now carries a TryFrom slice
bound so the shared from_slice body can construct the lane array.
@LaurenzV

Copy link
Copy Markdown
Collaborator

Just let me know if I should try it in vello!

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