www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - compile time tracing of d_do_test.d

reply Stefan Koch <uplink.coder googlemail.com> writes:
Hi Guys,

There's a tool running the dmd testsuite.
called d_do_test.d

It uses so much memory during compilation that the "-lowmem" 
switch is mandatory and it uses about as much time to compile as 
does dmd itself.

Interestingly in the case the reason is actually legitimately 
CTFE.

My profiling tool pointed to a function called unifyNewLines as 
the main time taker.
This was actually wrong.
But the real time taker was not far from it.

string unifyDirSep(string str, string sep)

For demonstration purposes, and because I am lazy, I did a quick 
hack to remove the CTFE from it

---
string unifyDirSep(string str, string sep)
{
     version(ctfe)
     {
     static Regex!char re  = 
regex(`(?<=[-\w{}][-\w{}]*)/(?=[-\w][-\w/]*\.(di?|mixin)\b)`, 
"g");
     return std.regex.replace(str, re, sep);
     }
     else
     {
     static Regex!char* re;
     if (re is null)
         (*re) = 
regex(`(?<=[-\w{}][-\w{}]*)/(?=[-\w][-\w/]*\.(di?|mixin)\b)`, 
"g");
     return std.regex.replace(str, (*re), sep);
     }
}
---

Take this function; put it into a file and compile that file.
If your configuration is anything like mine that'll take around 2 
seconds.
And it'll eat about 500 MB of ram
now compile that file with -version=ctfe
And you will see it taking 5 seconds and eating around 1.3GB of 
ram.

Cheers,

Stefan

P.S. Don't put your regex as initExp!
Jun 06 2020
parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Saturday, 6 June 2020 at 18:04:26 UTC, Stefan Koch wrote:

 And it'll eat about 500 MB of ram
 now compile that file with -version=ctfe
 And you will see it taking 5 seconds and eating around 1.3GB of 
 ram.
All I can say is... ouch.
Jun 06 2020