luau-lang / luau

A fast, small, safe, gradually typed embeddable scripting language derived from Lua
https://luau.org
MIT License
4.08k stars 382 forks source link

Optimize vector normalize and dot IR #1504

Closed green-real closed 2 weeks ago

green-real commented 3 weeks ago

Optimizes vector.normalize by using SIMD instructions, yielding a ~75% speed increase.

Optimizes vector.dot by reordering operations, yielding a ~20% speed increase.

zeux commented 2 weeks ago

How was the performance measured here - what hardware was used and what benchmarks were ran?

green-real commented 2 weeks ago

How was the performance measured here - what hardware was used and what benchmarks were ran?

For both benchmarks, I timed a for loop with a body that simply calls the function I am benchmarking with some non-constant arguments. Both benchmarks have been ran multiple times with around 1e8 iterations and were then averaged out which is where I got the percentages from. My benchmarks were ran on i7-11700.

Since it seems that your PR contains the same vector.normalize change as my PR and a way better vector.dot optimization, it would make sense to close this one in favour of yours.

aviralg commented 2 weeks ago

Merged PR #1512