Difference between revisions of "User talk:Laeeth"
(started to collect some tips on making D code fast for numerical computing - credit bearophile, Rob T, wb,) |
|||
Line 1: | Line 1: | ||
0. DMD flags:-O -release -inline -noboundscheck | 0. DMD flags:-O -release -inline -noboundscheck | ||
+ | LDC -O5 -release -inline -boundscheck=off | ||
+ | GDC -O3 -frelease -finline -fno-bounds-check | ||
0a. Use LDC or GDC | 0a. Use LDC or GDC |
Revision as of 17:44, 1 April 2015
0. DMD flags:-O -release -inline -noboundscheck
LDC -O5 -release -inline -boundscheck=off GDC -O3 -frelease -finline -fno-bounds-check
0a. Use LDC or GDC
1. Profile first; then optimize. For DMD: dmd -profile; also perf on Linux and AMD CodeAnalyst
2. Do foreach (y; 0 .. height) not foreach(y; (iota(height)))
3. Be careful with foreach on arrays of structs, because it performs copies that are slow if the structs aren't very small.
4. Sometimes in inner loops it's better to use a classic for instead of a foreach.
5. Be careful with classes, because on default their methods are virtual. Sometimes in D you want to use structs for performance reasons. Otherwise make all methods final
6. GC: Minimize situations where there's a lot of allocations going on while the GC is enabled because that will fire up the GC more often than is required and it can slow down your app significantly; A 2x or more performance penalty is certainly possible. It can also make performance unpredictable with large delays at inappropriate points in the execution.