# The Battle: Strassen vs AlphaEvolve vs Babylon. The winner will surprise you!

**URL:** <https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686>\
**Category:** Tutorials and tips\
**Created:** [May 27, 2025, 3:38pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686 "2025-05-27T15:38:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 27, 2025, 3:38pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/1 "2025-05-27T15:38:49Z")

</div>

I love how clickbait my title is 😄

Anyway! Yesterday, I fell headfirst into a glorious rabbit hole. I wanted to test the new matrix multiplication algorithm discovered by Google’s AlphaEvolve. This shiny new algorithm uses only **48 multiplications** , compared to **49 in Strassen’s** classic method—and **64 in Babylon.js’s** good ol’ matrix code (which I wrote _11 years ago_, so go easy on me, alright?).

On paper, I was thrilled. We use an _absurd_ number of matrix multiplications everywhere, and shaving off even a few per operation could be a massive win long-term.

So I whipped up a simple test comparing our naive implementation with Strassen’s—figuring I’d plug in AlphaEvolve’s version later, once I dig it out of their repo:  
👉 [Babylon.js Playground](https://playground.babylonjs.com/#RO25DY#6)

**The twist?** Babylon.js was _significantly_ faster than Strassen.

Wait, what? How is that even possible?

Here’s why:

| algorithm | multiplies | adds/subs |
| --- | --- | --- |
| naïve 4 × 4 | 64 | 48 |
| Strassen | **56** | **≈ 100 – 120** |

Strassen only saves **8 multiplications** (-12 %) but **more than doubles** the number of additions and temporary values.  
On a modern CPU (or in a JS JIT) an `x + y` is practically the same cost as `x * y`, so the “saving” is a wash — and all the extra adds, temporaries and memory traffic become pure overhead.

Also!

### Constant-factor overhead dominates

Strassen needs:

- Ten vector sums/differences (S1…S10).
- Seven internal 2 × 2 products.
- Four more vector combinations to build C.
- **~200 scalar loads/stores** versus 128 in the naïve path.

All that shuffling trashes the CPU’s L1 cache and the JavaScript engine’s register allocator. The naïve version, by contrast, is one straight-line block that the JIT can happily keep in registers and even auto-vectorise (SIMD / FMA).

### JIT & SIMD friendliness

- **Naïve** : tight, predictable access pattern → easy for V8/SpiderMonkey to hoist constants, unroll, and emit SIMD (FMA on x86: `c += a * b` in a single instruction).
- **Strassen** : scattered temporaries, larger code size → less chance of SIMD and often falls back to plain scalar ops.

## TL;DR

Strassen is an **asymptotic win** , not a micro-optimization. On a 4 × 4 matrix it:

- Saves _only_ eight multiplies.
- Adds ~70 more additions and loads/stores.
- Torpedoes SIMD/JIT optimisations.

So the plain old “schoolbook” kernel stomps it. _Congratulations to my naive self!_

---

<div class="post-metadata">

**Author:** ![georgie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/georgie/32/46049_2.png) [@georgie](https://forum.babylonjs.com/u/georgie)\
**Post date:** [May 27, 2025, 3:55pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/2 "2025-05-27T15:55:44Z")

</div>

This is so interesting/informative, thank you for sharing!!!

---

<div class="post-metadata">

**Author:** ![shaderbytes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shaderbytes/32/174_2.png) [@shaderbytes](https://forum.babylonjs.com/u/shaderbytes)\
**Post date:** [May 27, 2025, 8:50pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/3 "2025-05-27T20:50:15Z")

</div>

super cool that you took it for a spin to see real world outcomes .. based on your findings here it pretty much makes eveything about their annoucement useless.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 27, 2025, 10:01pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/4 "2025-05-27T22:01:22Z")

</div>

I think it still makes sense for hardware manufacturer if they want to have hardware matrix multiplication because at silicon level an addition is far less expensive than a mul

---

<div class="post-metadata">

**Author:** ![cyborg\_ean](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cyborg_ean/32/42302_2.png) [@cyborg\_ean](https://forum.babylonjs.com/u/cyborg_ean)\
**Post date:** [May 28, 2025, 3:41am UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/5 "2025-05-28T03:41:48Z")

</div>

This was a satisfying read. I think it’s a great opportunity for a post mordem @Deltakosh. I’d love to hear about the thinking behind decisions you made in your “naive” algorithm over a decade ago, how it shaped modern BabylonJS, and perhaps what you’d do differently today.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [May 28, 2025, 4:06am UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/6 "2025-05-28T04:06:45Z")

</div>

> [@Deltakosh](#):
>
> Congratulations to my naive self!

🫡

Look, on Apple M4:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/0/20a20bdc874bea94b04b796ff7cdc0f0948198f4.jpeg)

Ok, ok, relax, it’s just a very late April Fools’ joke.  
` console.log("Strassen:", delay1 * 0.6356);` 🙈 🤪

When Google’s AI discovered the new ‘magic’ matrix multiplication algorithm, I was instantly curious whether it would provide a real performance boost. I was waiting for a real-world scenario benchmark and now we have the results, delivered directly by the Master himself. Thanks for trying it out and sharing the findings! Once again, Google has proven they can generate a lot of hype around empty achievements.

Humans vs AI  
1 : 0

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 28, 2025, 3:46pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/7 "2025-05-28T15:46:54Z")

</div>

Nice try! At the beginning I was like: oh fuck…

That would not be the first time Apple would be doing things differently 😃

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 28, 2025, 3:47pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/8 "2025-05-28T15:47:36Z")

</div>

Haha. That will be fast: I ported the code from my previous engine 😉

And for that engine, I was not giving it a lot of thoughts 😃

---

<div class="post-metadata">

**Author:** ![lowclouds](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lowclouds/32/26590_2.png) [@lowclouds](https://forum.babylonjs.com/u/lowclouds)\
**Post date:** [June 2, 2025, 7:10pm UTC](https://forum.babylonjs.com/t/the-battle-strassen-vs-alphaevolve-vs-babylon-the-winner-will-surprise-you/58686/9 "2025-06-02T19:10:36Z")

</div>

looked through the PDP-11 manual and saw no references to SIMD, huh.  
but, 8.88 usec for a floating point add and 29.8 usec for a floating point multiply.
