nsf/pnoise — pull request #5 by Tipaa (2014-08-24 06:40:36+00:00)
Title: Optimise D to be on par with C and Rust

One of the biggest differences is changing from `@safe` to `@trusted`. `@safe` enforces that all checks like bounds, contracts, invariants etc. are always included, even in a release build. `@trusted` *acts* like `@safe`, but doesn't include these safety checks, since it trusts your code to be `@safe` on its own. Also, making everything immutable was really good for speeding up the code, since it meant that the compiler can optimise more (implicit immutability should probably be default in many of the compilers of today).

Then after `perf` said half of my CPU time was on `float floor(float)` and the other half on memory, I `alias`ed floor to use `core.stdc.math` instead of `std.math`, bypasing some of D's safety for massive speed gains. I also looked at the Rust code after that and changed the algorithm from pure OO (N2DContext containing the last origin/gradient states) into more data-oriented, using the Rust algorithm (the same, except `Vec2[4] origin, gradients` are the return values of `get_gradients` instead of members of N2DContext, bypassing a write, cache miss and memory access). This pipped Rust by a small amount on GDC, and was pipped by Rust on LDC. All three beat the current GCC/C code on my machine.