Speeding up importing Phobos files
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Jan 19 19:56:29 UTC 2019
On Sat, Jan 19, 2019 at 06:05:13PM +0000, Neia Neutuladh via Digitalmars-d wrote:
[...]
> I compiled one file with one extra -I directive as a test. The file
> had two imports, one for url.d (which depends on std.conv and
> std.string) and one for std.stdio.
>
> For each transitive import encountered, the compiler:
> * looked at each import path (total of four: ., druntime, phobos, and
> urld's source dir)
> * looked at each possible extension (.d, .di, and none)
> * built a matching filename
> * checked if it existed
>
> Maybe it should do a shallow directory listing for the current
> directory and every -I path at startup, using that information to
> prune the list of checks it needs to do. It could also do that
> recursively when importing from a subpackage. Then it would have
> called 'opendir' about four times and readdir() about 70 times; it
> wouldn't ever have had to call exists(). It would allocate a lot less
> memory. And that's a change that will help people who don't zip up
> their source code every time they want to compile it.
[...]
Excellent finding! I *knew* something was off when looking up a file is
more expensive than reading it. I'm thinking a quick fix could be to
just cache the intermediate results of each lookup, and reuse those
instead of issuing another call to opendir() each time. I surmise that
after this change, this issue may no longer even be a problem anymore.
T
--
It is of the new things that men tire --- of fashions and proposals and improvements and change. It is the old things that startle and intoxicate. It is the old things that are young. -- G.K. Chesterton
More information about the Digitalmars-d
mailing list