Speeding up importing Phobos files

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jun 8 07:12:41 UTC 2019


On 1/21/19 2:35 PM, Neia Neutuladh wrote:
> On Mon, 21 Jan 2019 19:10:11 +0000, Vladimir Panteleev wrote:
>> On Monday, 21 January 2019 at 19:01:57 UTC, Steven Schveighoffer wrote:
>>> I still find it difficult to believe that calling exists x4 is a huge
>>> culprit. But certainly, caching a directory structure is going to be
>>> more efficient than reading it every time.
>>
>> For large directories, opendir+readdir, especially with stat, is much
>> slower than open/access.
> 
> We can avoid stat() except with symbolic links.
> 
> Opendir + readdir for my example would be about 500 system calls, so it
> breaks even with `import std.stdio;` assuming the cost per call is
> identical and we're reading eagerly. Testing shows that this is the case.

Another simple test:

import std.experimental.all;
void main(){}

Use "time -c test.d". On my SSD laptop that takes 0.55 seconds. Without 
the import, it takes 0.02 seconds. In an ideal world there should be no 
difference. Those 0.53 seconds are the upper bound of the gains to be 
made by first-order improvements to import mechanics. (IMHO: low impact 
yet not negligible.)


More information about the Digitalmars-d mailing list