Discussions about the performance of code fragments pop up regularly on the dlang forums. Why is this much faster than that? Does `immutable` make my code faster? Is a range-based loop faster than a normal loop? Without understanding the LDC optimization process and capabilities, it's not so easy to do good performance measurements and comparisons; the discussions often lack good data.
Using Matt Godbolt's D compiler explorer, I will live demonstrate and explain the optimized LDC assembly output for basic D code patterns. Common pitfalls and how to avoid them will be discussed. A small selection of topics: virtual functions, Voldemort types, aggregate comparisons, when does immutable/const matter?, inline assembly, ranges or for-based iteration. The results are often surprising, so for extra fun, I'll poll the audience before showing the assembly output. After this talk, you'll be better prepared for the next forum.dlang.org performance thread.
Takeaway points: have a better understanding of the zero/non-zero runtime costs of certain D constructs, awareness of common pitfalls and useful tools for analyzing why a certain piece of code is/isn't performant.
Johan Engelen is one of the core LDC developers. He is also a D compiler consultant for Weka.io (probably the largest industrial single-executable D codebase) and maintains and adds features to their fork of LDC. While working on LDC, he often studies the compiler output IR and assembly. To aid this, he helped setting up LDC at d.godbolt.org. Examples of his recent contributions to LDC related to optimization are @fastmath, link-time optimization (LTO) and profile-guided optimization (PGO).
Johan (PhD Electrical Engineering) is assistant professor in the Robotics and Mechatronics (RAM) group at the University of Twente, the Netherlands. In his spare time he has contributed large amounts of work to the open source projects LDC and Inkscape.