Thread overview
Why exe size change if import entire std or just writeln?
Mar 24, 2022
Marcone
Mar 24, 2022
H. S. Teoh
Mar 25, 2022
Salih Dincer
March 24, 2022

import std.stdio : writeln;

void main(){
writeln("Bom dia");
}

Size exe file: 258 KB


import std;

void main(){
writeln("Bom dia");
}

Size exe file: 595 KB

If dependencies are resolved at compile time, why does the compiler include extra stuff?

March 23, 2022
On Thu, Mar 24, 2022 at 01:49:30AM +0000, Marcone via Digitalmars-d-learn wrote:
> import std.stdio : writeln;
> 
> void main(){
> 	writeln("Bom dia");
> }
> 
> 
> Size exe file: 258 KB
> 
> --------------------------------------------------------------
> 
> import std;
> 
> void main(){
> 	writeln("Bom dia");
> }
> 
> Size exe file: 595 KB
> 
> 
> 
> If dependencies are resolved at compile time, why does the compiler include extra stuff?

Did you compile with LTO?  If not, the exe may carry extra baggage, since the linker may not have tried to shed excess baggage.


T

-- 
My father told me I wasn't at all afraid of hard work. I could lie down right next to it and go to sleep. -- Walter Bright
March 25, 2022

On Thursday, 24 March 2022 at 01:49:30 UTC, Marcone wrote:

>

If dependencies are resolved at compile time, why does the compiler include extra stuff?

You are right! Test results on linux:

//import std.stdio : writefln;/*
version = 1;
import core.stdc.stdio : printf;//*/


void main()
{
  string hello = "hello";

  version(1)
  {
    printf("%s world\n", hello.ptr);// 6464 bytes with strip
  }

  else hello.writefln!"%s World!";  // 196KB with strip
}
/*
 * ldc2 -O hello.d -release
 */