Brian Robert Callahan

submited by
Style Pass
2021-05-30 16:00:09

If you care about performance, at some point you will need to use some tools to understand where the performance issues with your programs are. Do not assume that you can read the code and know where the performance problems lie: you will often be very wrong, spending a lot of time trying to optimize that which does not need it and fail to optimize that which does.

Let's spend some time today optimizing our assembler. I know it is already very fast, but I suspect we can make at least a couple of improvements. We can use a technique called profiling to learn about what our assembler is really doing during an invocation. Profiling is quite an old technique but it is still quite powerful. We won't dive into all the different kinds of profilers out there; we will pick one profiling tool and just use it. We're just learning about profiling today, after all.

The DMD compiler is the reference compiler for D. It provides a command line switch, -profile, that profiles runtime performance of the program it compiles. There is also an additional profiling switch, -profile=gc, which profiles memory. I don't care so much about profiling memory; our assembler is a very short-lived program that takes the traditional memory management approach of having no memory management. So we will only add the -profile switch to our DMD compilation. There is also a way to automagically do this work with DUB: dub build -b profile. I am going to use that dub invocation to make sure everything goes right.

Leave a Comment