Clean Code, Horrible performance Rust edition !
Hello Rustaceans,
In his infamous video "Clean" Code, Horrible Performance, the legendary Casey Muratori showed how trying to be cute with your code and introducing unnecessary indirection can hurt performance. He compared the “clean” code way of structuring your classes in an "OOP" style, using class hierarchy, virtual functions, and all the hoopla. He then showed how writing a straightforward version using union struct can improve by more than 10x the “clean” code version.
The goal of this simple implementation article is to see what a Rust port of the video would look like from an idiomatic-rust style feel and of course performance. The results show
The enum version is 1.6x faster than using traits + dynamic dispatch.
EDIT: after fixing a bug thanks The data oriented version is 1.65x faster than dynamic one.
Hope you'll enjoy this short article and I'd be happy to get comments on the implementation and the subject in general!