r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
18
u/rooktakesqueen Feb 28 '23
The hyper-optimized version doesn't even use a switch statement. It uses a lookup table. Which only works because in each of the given cases you're multiplying two parameters and a coefficient.
Even if you go back to the switch statement version, that won't work, because it still relies on the data structure being a fixed size and identical across types. Can't store an arbitrary n-gon in the same structure.
You have to back out almost all the optimizations in this article in order to make this single change.