Difference between revisions of "User talk:Laeeth"

From D Wiki
Jump to: navigation, search
 
Line 1: Line 1:
0. DMD flags:-O -release -inline -noboundscheck
+
Notes on using D for performance-efficient code
   LDC -O5 -release -inline -boundscheck=off
+
-----------------------------------------------
   GDC -O3 -frelease -finline -fno-bounds-check
+
 
 +
  dmd -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

Latest revision as of 17:45, 1 April 2015

Notes on using D for performance-efficient code


  dmd -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.