How to figure out which part of my d code takes long time to compile?
I tried to use valgrind, but the the method names were not very insightful. 87% of time was spent in <cycle 7>
, 40% of the time in _D4ddmd5lexer5Lexer4scanMFPS4ddmd6tokens5TokenZv
I'm looking for something like this: 40% of the time was spent on xy.d
, out of that 80% of the time took compiling various instantiations of template xyz
and a reason is because it used memcpy
99% of the time.
I'm interested profiling both DMD and LDC.
As the D compiler front end is written in D, profiling using conventional tools will be rather hard compared to something like C++. I have had some success using tools like gdb and valgrind on Linux and tools like VisualD on Windows, Mac users are kind of SOL.
You have five other options:
-v
flag to try and see which parts of your program take a while. Granted, this is a very brute force approach and can take you a while.-profile
switch. Every time you run DMD you will get a profile file with a lot of information. Granted, I don't think this has ever been tried. Your milage may vary.When I say turn to common knowledge, I mean to say that your slow compilation is likely due to a few common problems. For example, when an SQL query is taking too long, my first reaction is not to try to profile the MySQL server code. Here are a couple of the most common issues
allSatisfy
or your using functions like ctRegex
. If you're doing heavy CTFE and you want faster compiles at the price of possible slower code, consider switching them to run time calls.import std.algorithm;
or import std.range;
. Instead use package specific imports like import std.algorithm.iteration : map;
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With