Thread overview
std.format with wstring and dstring
22 hours ago
Robert Schadek
21 hours ago
monkyyy
15 hours ago
Robert Schadek
1 hour ago
IchorDev
1 hour ago
Dom DiSc
22 hours ago

I spend one day at dconf this year and removed wstring and dstring support from
std.format to improve compile speed. std.format.FormatSpec is no longer a template
on the character type, and the bitfield template was removed as well.

The dub package can be found here https://code.dlang.org/packages/std2_format
https://github.com/burner/std2.format

When compiling the below format call with ldc and -ftime-trace

import std2.format;
//import std.format;

void main(){
    string s = format("Hello %s %s %.2f", "World", 1337, 13.37);
    assert(s == "Hello World 1337 13.37", s);
}

The overall compile time decreases from 290ms to 223ms and the frontend time for
the format call goes from 71ms to 23ms.

Currently, alias this and toString tests fail. And I can't really figure out why.
Also some float tests fails.

PR's are always welcome.

Meta: Removing wstring and dstring support from std.format for phobos 3 should be looked at IMHO.

21 hours ago

On Sunday, 7 September 2025 at 12:29:08 UTC, Robert Schadek wrote:

>

I spend one day at dconf this year and removed wstring and dstring support from
std.format to improve compile speed. std.format.FormatSpec is no longer a template
on the character type, and the bitfield template was removed as well.

The dub package can be found here https://code.dlang.org/packages/std2_format
https://github.com/burner/std2.format

When compiling the below format call with ldc and -ftime-trace

import std2.format;
//import std.format;

void main(){
    string s = format("Hello %s %s %.2f", "World", 1337, 13.37);
    assert(s == "Hello World 1337 13.37", s);
}

The overall compile time decreases from 290ms to 223ms and the frontend time for
the format call goes from 71ms to 23ms.

Currently, alias this and toString tests fail. And I can't really figure out why.
Also some float tests fails.

PR's are always welcome.

Meta: Removing wstring and dstring support from std.format for phobos 3 should be looked at IMHO.

wouldnt be far faster to just rip out all the c api complexity and just do a simple sane api?

15 hours ago

On Sunday, 7 September 2025 at 13:15:21 UTC, monkyyy wrote:

>

wouldnt be far faster to just rip out all the c api complexity and just do a simple sane api?

No, not at all. The compile time goes into all the duck typing of toString on classes and structs and nested formats like %(%s,%)

9 hours ago
std.format is on my list of modules that I want replaced.

Its written with a lot of error conditions, rather than just adapting to the inputs. Hence lots of potential for exceptions being thrown that don't need to be.

Multiple multipliers in ``formattedWrite``: format string, output range.

What I'd like to do is to force IES for one or more values, if you want finer grained control you want do one value a time (``formatValue``).

```d
writeln(i"$i ${i:X}: $(j + 1)/${(j + 1):X} $1 ${0:X}", k, obj, "atend");
```

Require the use of a string builder, rather than any old output range.
This is a required change for pretty printing. It requires the use of arbitrary inserts and removals that ranges can't do.

Every template parameter like these that you have is a multiplier of instances, and that isn't good for compile times. Simplifying them down may seem like a pain, but it helps quite significantly. Given that there are some clear requirements and use cases we can in fact simplify it without hurting anyone enough to care.
1 hour ago

On Sunday, 7 September 2025 at 12:29:08 UTC, Robert Schadek wrote:

>

Meta: Removing wstring and dstring support from std.format for phobos 3 should be looked at IMHO.

As I understand it, Phobos 3 will basically not support UTF-16 or UTF-32 anymore except for encoding conversion. As someone who appreciates UTF-32's elegant simplicity, I find this saddening.

1 hour ago

On Monday, 8 September 2025 at 08:49:53 UTC, IchorDev wrote:

>

On Sunday, 7 September 2025 at 12:29:08 UTC, Robert Schadek wrote:

>

Meta: Removing wstring and dstring support from std.format for phobos 3 should be looked at IMHO.

As I understand it, Phobos 3 will basically not support UTF-16 or UTF-32 anymore except for encoding conversion. As someone who appreciates UTF-32's elegant simplicity, I find this saddening.

This "simplicity" is gone in the moment you start working with graphemes. A "unit" on the screen may consist of multiple characters no matter which encoding you use - so why not stay with a single one (UTF-8)?