DIP10005: Dependency-Carrying Declarations is now available for community feedback

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 22 05:09:51 PST 2016


On 12/22/2016 05:17 AM, Joakim wrote:
> On Wednesday, 21 December 2016 at 15:16:34 UTC, Andrei Alexandrescu wrote:
>> In first approximation, whether a file gets opened or not makes a
>> difference (filesystem operations (possibly including networking),
>> necessity to rebuild if dependent code is changed. The analysis shows
>> there is significant overhead remaining, on average 10.5 additional
>> files per unused import.
>
> Opening a file or 10 is extremely cheap compared to all the other costs
> of the compiler.  Purely from a technical cost perspective, I'm not sure
> even scoped imports were worth it, as my simple investigation below
> suggests.

This is a misunderstanding. (I'll make the DIP clearer.) It's not about 
the cost of opening the file per se; I'm using the number of files 
opened as a proxy for all work involved in processing a file. Meaning, 
if you import 10 files you're likely to do roughly 10x the work of 
importing one file.

> I just tried compiling phobos and its unittests for dmd 2.066.1 and
> 2.067.1, the dmd releases from right before and right after Ilya's PRs
> linked above (compiling phobos from the older release with the newer dmd
> didn't work and I wasn't interested in porting it).  I found they took
> about the same amount of time to compile their respective phobos and the
> later version consistently took 15 seconds longer to compile the
> unittests on a single core.

Unittesting Phobos (whether in separation or together) will instantiate 
everything so they are the case when local imports do _not_ make any 
difference. That's why DIP1005 uses that case as an estimate of 
everything in an imported module being used.

Compiling Phobos in its entirety (one command) and measuring that time 
is also of tenuous relevance; I need to think of it but at first sight 
the cost of unnecessary imports is collapsed, and I suspect (and will 
measure) that either way most modules are in fact imported.

One measurement of interest is: write a module that imports exactly one 
stdlib module, compile it, and measure time. Looking at the generated 
object and executable size would be also of interest. I'll do that.

> This suggests that there has been essentially no technical benefit to
> scoped imports, that it is largely superficial.  That's fine, I think
> it's worth it just from the standpoint of understanding where most
> dependencies are coming from.  I don't think an additional syntax change
> is necessary for the remaining few module-scope dependencies for
> template constraints.
>
> Note on investigation: Of course, some other relevant factors could have
> changed in dmd and phobos between those two releases, so the result is
> certainly not conclusive.  But the fact that there was no decrease in
> compile times while phobos took around the same amount of time is highly
> suggestive.
>
> I'm uninterested in investigating further given the consistent
> hand-waving justifications for this DIP.  If somebody else had submitted
> this DIP, it would have been quickly shot down, and rightly so.

Walter and I have the role of scrutinizing every addition to the 
language (and reject most). It is natural that our own work is met with 
increased scrutiny. Picking to death anything and everything we say or 
do is a staple in this community, and a rite of passage on github. It is 
of course impossible to know what would have happened if the proposal 
were made by someone else. All I can say is Walter knew nothing about it 
and said it is good (except for the initial syntax; he's on board with 
"with").

Anyhow, not to worry. The burden of proof is on the DIP. I'll take a 
look at making some more measurements.


Andrei



More information about the Digitalmars-d mailing list