Speeding up importing Phobos files

Adam D. Ruppe destructionator at gmail.com
Tue Jan 22 03:18:45 UTC 2019


On Monday, 21 January 2019 at 21:38:21 UTC, Steven Schveighoffer 
wrote:
> One note -- I don't think modules like std.datetime were split 
> up for the sake of the compiler parsing speed

Yeah, I think std.datetime was about the size of unittest runs, 
but std.range, as I recall at least, was specifically to separate 
stuff to get quicker builds by avoiding the majority of the 
import for common cases via std.range.primitives which doesn't 
need to bring in as much code. The local import pattern also 
helps with this goal - lazy imports to only get what you need 
when you need it, so the compiler doesn't have to do as much work.

Maybe I am wrong about that, but still, two files that import 
each other aren't actually two modules. Phobos HAS been making a 
LOT of progress toward untangling that import mess and addressing 
specific compile time problems. A few years ago, any phobos 
import would cost you like a half second. It is down to a quarter 
second for the hello world example. Which is IMO still quite 
poor, but a lot better than it was.

But is this caused by finding the files?

$ cd dmd2/src/phobos
$ time find .
real    0m0.003s

I find that very hard to believe.

And let us remember, old D1 phobos wasn't this slow:

$ cat hi.d
import std.stdio;

void main() {
         writefln("Hello!");
}

$ time dmd-1.0 hi.d

real    0m0.042s
user    0m0.032s
sys     0m0.005s

$ time dmd hi.d

real    0m0.434s
user    0m0.383s
sys     0m0.044s



Using the old D compilers reminds me what quick compiles REALLY 
are. Sigh.


More information about the Digitalmars-d mailing list