std.conv.to!string(float) Is too heavy

Hipreme msnmancini at hotmail.com
Tue Oct 12 18:00:42 UTC 2021


On Tuesday, 12 October 2021 at 17:35:31 UTC, russhy wrote:
> On Tuesday, 12 October 2021 at 14:47:21 UTC, Hipreme wrote:
>> I have wrote a simple hello world using std.conv:
>>
>>
>> ```
>> import std.conv:to;
>> import std.stdio;
>>
>> export void MAIN(float b)
>> {
>> 	writeln("Hello World " ~ to!string(b));
>> }
>> ```
>>
>> Building that with dmd app.d -lib creates 500KB lib
>> With `-g`, it goes up to 800KB
>>
>> Using ldc, the build time goes up by 2 times.
>>
>> if you simply change from `float b` to `int b`, the lib goes 
>> down from 500KB to 60KB.
>> The build times decreases by almost 10x (must check), but I 
>> can feel that anyway.
>>
>> Using std.conv greatly degrades a modularized workflow, by 
>> increasing a lot of build time and binary size. I needed 
>> implementing my own to! function to get a much better build 
>> time for my program.
>
>
> try to build with:
>
> ```json
> "dflags-ldc": [
>     "-linkonce-templates",
> ],
> ```
>
>
> i'd personally suggest using snprintf, but depending on your 
> usecase that might not be perfect
>
> ```d
> char[32] tmp = 0;
> snprintf(tmp.ptr, tmp.length, "Hello World %f", value);
> ```


snprintf can't be called at compile time, so, it can miss a lot.
That flag didn't seem to do something


More information about the Digitalmars-d mailing list