long compile time question

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 24 10:45:13 PDT 2012


On Wed, Oct 24, 2012 at 06:04:10PM +0200, Don Clugston wrote:
> On 24/10/12 17:39, thedeemon wrote:
> >On Wednesday, 24 October 2012 at 03:50:47 UTC, Dan wrote:
> >>The following takes nearly three minutes to compile.
> >>The culprit is the line bar ~= B();
> >>What is wrong with this?
> >>
> >>Thanks,
> >>Dan
> >>----------------
> >>struct B {
> >>  const size_t SIZE = 1024*64;
> >>  int[SIZE] x;
> >>}
> >>
> >>void main() {
> >>  B[] barr;
> >>  barr ~= B();
> >>}
> >>-----------------
> >
> >The code DMD generates for initializing the struct does not use loops,
> >so it's
> >xor     ecx, ecx
> >mov     [eax], ecx
> >mov     [eax+4], ecx
> >mov     [eax+8], ecx
> >mov     [eax+0Ch], ecx
> >mov     [eax+10h], ecx
> >mov     [eax+14h], ecx
> >mov     [eax+18h], ecx
> >mov     [eax+1Ch], ecx
[...]

Yikes!! Why aren't we using memset (or equivalent) here?!


> That's incredibly horrible, please add to bugzilla.
[...]

Yeah, no kidding! For comparison, GDC does a way better job in this
department:

	$ time dmd test.d

	real    0m7.564s
	user    0m7.529s
	sys     0m0.029s
	$ time gdc test.d

	real    0m0.107s
	user    0m0.069s
	sys     0m0.036s
	$

This is with SIZE = 1024*16 (I didn't dare try it with 1024*64).  That's
a 75:1 ratio between dmd and gdc, which is pretty horrible, since dmd is
usually significantly faster than gdc.

Surprisingly, though, dmd still produces a smaller executable than gdc
for this code! I'm guessing the optimizer cleans up that code
afterwards? (Or maybe there are other factors at play here that I'm not
aware of.)


T

-- 
EMACS = Extremely Massive And Cumbersome System


More information about the Digitalmars-d-learn mailing list