You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SIMD] Support optimal 4x4 matrix multiplication. #64238
I wanted to share where we stand on being able to support optimal 4x4 matrix multiplication via our typed_data SIMD APIs so it can be used by e.g. Flutter for close to optimal performance.
As of today, Flutter uses scalar matrix multiplication (matmul).
Vectorized matmul is roughly 1.5x~ faster. With shuffle optimizations that are on my radar (SIMD tracking issue. #64170) we should be able to make it 2.5x~.
However, to get optimal 4x4 matmul, we need something known as the indexed fmla which allows us to not splat + fma, but use a single chain of indexed fmla instructions for implementing 4x4 matmul.
Wasm SIMD doesn't support indexed fmla, which costs us roughly 30% compared to splat+fma (which is still a nice 5x~ perf gains over scalar! cc @kevmoo).
Optimal matmul gives use almost 6x faster 4x4 matmul on the VM. Given that matmul is a very important operation in Flutter, squeezing out the last 30%~ seems worthwhile.
vector_math was designed on the typed_data bits - as they were many years ago
it's also designed to support 32- and 64-bit numbers.
Flutter only uses the 64-bit bits
vector_math is now owned by the Flutter team (more or less)
I'm a BIG fan of saying we should strip vector_math down to focus on just what Flutter needs.
The current model uses a simple copy-paste-rename model to generate 64-bit bits from 32-bit bits.
I've already done a pass on optimizing vector_math - but there is a LOT of low-hanging fruit here. Especially if we drop this notion that the 64-bit path is just a slightly tweaked version of the 32-bit path.
☝️ Is product hand waving, speculation, and wishful thinking. But I'm happy to engage with you on it!
Given that matmul is a very important operation in Flutter, squeezing out the last 30%~ seems worthwhile.
It would be nice to quantify this by some sort of Flutter benchmark, which is not a microbenchmark (e.g. it does actual UI rendering and demonstrates that Matrix multiplication is on the hot path). 30% of 50% is "sure, it's worthwhile", 30% of 10% is "maybe, it's worthwhile" and 30% of 5% is pretty much "it's irrelevant".
Activity
kevmoo commentedon Sep 8, 2026
I LOVE that you're digging in here @modulovalue !
Some notes:
vector_mathwas designed on the typed_data bits - as they were many years agovector_mathis now owned by the Flutter team (more or less)☝️ Is product hand waving, speculation, and wishful thinking. But I'm happy to engage with you on it!
mraleph commentedon Sep 9, 2026
It would be nice to quantify this by some sort of Flutter benchmark, which is not a microbenchmark (e.g. it does actual UI rendering and demonstrates that Matrix multiplication is on the hot path). 30% of 50% is "sure, it's worthwhile", 30% of 10% is "maybe, it's worthwhile" and 30% of 5% is pretty much "it's irrelevant".