www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can compiler profile itself?

reply Profile Anaysis <PA gotacha.com> writes:
I am trying to compile some code and it takes around 6 seconds. 
Even if I change one line in one module, it takes the same time. 
There are about 20 different d modules.

I used to get around 1-2 second compile times several months ago 
on different projects.

I did upgrade a few things and it seems that something has made 
things slow.

Can we ask the compiler what seems to be taking the most time(a 
module, a template, etc...)?

If the compiler can profile itself then it would be very easy to 
figure out what is slowing things down in compilation.

I feel that I should be able to compile all the modules 
separately and only have to recompile the module that I 
changed... and that it should be quite fast(e.g., if the module 
contains nothing but the main and a write statement, regardless 
of all the other stuff in the project, I'd expect that to be 
fast).

For example, If I do the

import std.stdio;

int main(string[] argv)
{
     writeln("Hello D-World!");
     return 0;
}

it takes <1s.

Yet if I import a bunch of modules it takes 6+s and the time 
never reduces on subsequent builds.

I am using Visual D.

Visual D has a separate compile and link feature but when I try 
it for dmdx64 I get

Internal error: backend\mscoffobj.c 2016

It does work for x32 but the speed does not change.

I'm convinved that dmd is recompiling everything each time... and 
this doesn't seem very fast IMO when less than 0.1% of the 
project has changed.
Jan 24
parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Tuesday, 24 January 2017 at 23:25:12 UTC, Profile Anaysis 
wrote:
 I am trying to compile some code and it takes around 6 seconds. 
 Even if I change one line in one module, it takes the same 
 time. There are about 20 different d modules.

 [...]
yes the compiler can be used to profile itself. build it with make ENABLE_PROFILE=1 If your code is overly slow you are probably using recursive variaidic templates.
Jan 25
parent Profile Anaysis <PA gotacha.com> writes:
On Wednesday, 25 January 2017 at 12:49:05 UTC, Stefan Koch wrote:
 On Tuesday, 24 January 2017 at 23:25:12 UTC, Profile Anaysis 
 wrote:
 I am trying to compile some code and it takes around 6 
 seconds. Even if I change one line in one module, it takes the 
 same time. There are about 20 different d modules.

 [...]
yes the compiler can be used to profile itself. build it with make ENABLE_PROFILE=1 If your code is overly slow you are probably using recursive variaidic templates.
Would it not be easier to have this feature as a command line argument that enables it in the compiler or include a compiler version that does this? Not all everyone is good at building from sources...
Jan 25