December 14, 2022
On Wed, Dec 14, 2022 at 07:38:51PM +0000, torhu via Digitalmars-d wrote:
> On Wednesday, 14 December 2022 at 01:47:29 UTC, Steven Schveighoffer wrote:
> > 
> > ```d
> > void main() @nogc
> > {
> >    import std.conv;
> >    auto v = "42".to!int;
> > }
> > ```
> 
> 
> I have been wondering why there isn't a basic variation like this available:
> 
> ```d
> auto i = "42".toOr!int(-1);
> auto s = i.toOr!string(null);
> ```

This would be a nice addition to Phobos IMO.  Though we should think of a better name for it. :-P


T

-- 
Never step over a puddle, always step around it. Chances are that whatever made it is still dripping.
December 15, 2022

On Wednesday, 14 December 2022 at 20:30:39 UTC, H. S. Teoh wrote:

>

On Wed, Dec 14, 2022 at 07:38:51PM +0000, torhu via Digitalmars-d wrote:

>

On Wednesday, 14 December 2022 at 01:47:29 UTC, Steven Schveighoffer wrote:

>
void main() @nogc
{
   import std.conv;
   auto v = "42".to!int;
}

I have been wondering why there isn't a basic variation like this available:

auto i = "42".toOr!int(-1);
auto s = i.toOr!string(null);

This would be a nice addition to Phobos IMO. Though we should think of a better name for it. :-P

T

Maybe we could've enhanced to itself had we named arguments in the language

auto c = "42".to!int(error = <whatever value you want>);

Or maybe a result type would be enough, so no need for this?

December 15, 2022

On Wednesday, 14 December 2022 at 11:12:52 UTC, cc wrote:

>

couldn't work around. It doesn't matter if the actual delay caused by a GC pause is minimal, if those delays cause significant recurring hiccups and timing errors. Allocations and deallocations had to be more deterministic, ultimately it came down to the decision that with the need to offload or reschedule memory management to be more distributed, working around the GC would be more trouble than just avoiding it in the first place.

Probably this is common case when your program works in tight loop - like game, or webserver under high load. Process just have no spare time to handle GC cleanups (for stop-the-world collectors).

December 15, 2022

On Thursday, 15 December 2022 at 08:42:22 UTC, ikod wrote:

>

Probably this is common case when your program works in tight loop - like game, or webserver under high load. Process just have no spare time to handle GC cleanups (for stop-the-world collectors).

One interesting observation here in the forum and also in articles, blogs etc about the D garbage collector about how you can speed up memory management. All those ideas and tricks are based on that you in some way should avoid or circumvent the garbage collector. Then the question is, how good is a computer algorithm if you are supposed to avoid it all the time?

Also, it doesn't matter if "the GC stop world" duration are very short. It takes time for the OS scheduler to stop all thread which probably is a significant part of the GC pause. Then depending on the load the is also a duration until the thread is started again.

December 16, 2022
On 16/12/2022 12:21 AM, IGotD- wrote:
> All those ideas and tricks are based on that you in some way should avoid or circumvent the garbage collector. Then the question is, how good is a computer algorithm if you are supposed to avoid it all the time?

Like all algorithms, if you misuse it its going to be bad.

Calling into the GC unnecessarily when you care about performance is misuse.

December 15, 2022
On Thursday, 15 December 2022 at 11:21:56 UTC, IGotD- wrote:
> ... Then the question is, how good is a computer algorithm if you are supposed to avoid it all the time?
> ...

To be honest I don't think people generally are bothered with this. I mean when I write my batch programs to process something in D or C# I don't even think about the GC stopping or whatever, most of the time it will process some data in a reasonable time so I'm OK.

The other day I had to write a program to comparable the sync between 2 different databases and check the differences over millions of lines. The program ran very fast and gave the result expected in a very reasonable time.

Of course in some areas this may hurt (Like games) and then you will need to think of ways to avoid it.

But for example imagine a drawing app, let's say you're filling an area and during this process the GC stops for a second. I mean will this make so much difference?

Yes some people will notice this, but the majority will not even think or know this happened.

Where I work (Which is a big Health Insurance in my country), our main language is C# and we process millions of data every day, apps, web apps etc. And nobody is complaining too much about the delay in our operations.

Matheus.
December 15, 2022
On Thursday, 15 December 2022 at 11:56:31 UTC, matheus wrote:
>
> To be honest I don't think people generally are bothered with this. I mean when I write my batch programs to process something in D or C# I don't even think about the GC stopping or whatever, most of the time it will process some data in a reasonable time so I'm OK.
>

Majority of applications are so small and have little performance requirements that it doesn't matter. It starts to matter when you have web services, games etc. For example if you reduce the memory consumption, perhaps you don't need to buy/hire that extra infrastructure which cost money.


> Where I work (Which is a big Health Insurance in my country), our main language is C# and we process millions of data every day, apps, web apps etc. And nobody is complaining too much about the delay in our operations.
>

The default GC in C# is generational which is also a workaround of the inefficiency of the algorithm. C# has at least the luxury to use several different types of GC which might be more of them in the future.

I'm amazed how much the tracing GC is used in the computer industry despite its complexity and drawbacks. When will the time come when the tracing GC no longer scales with increasing memory consumption?




December 15, 2022
On Thursday, 15 December 2022 at 12:36:59 UTC, IGotD- wrote:
> I'm amazed how much the tracing GC is used in the computer industry despite its complexity and drawbacks. When will the time come when the tracing GC no longer scales with increasing memory consumption?

We will most likely see coprocessors working on regular memory, and like now, people will use no-gc libraries for the low latency heavy lifting. Another hardware solution would be to let cores have local memory, then people will switch to pushing data as values through a pipeline and avoid references. That would scale well, but requires developers to switch to a new more "functional" mindset.

Anyway, concurrent collectors that don't stop the world are not as bad if you add hardware capabilities that prevents the caches for being flushed and the data-bus from being saturated. You could have a separate hardware-cache for book-keeping tasks and just slowly scan memory in the background rather than the hit-and-run approach.

Besides, most applications don't really need the full capabilities of modern hardware so the users don't mind applications being slow as they don't "understand" that they are actually slow… :-) That's what makes javascript and dart competitive for application development.


December 15, 2022

On Wednesday, 14 December 2022 at 03:20:13 UTC, Steven Schveighoffer wrote:

>

On 12/13/22 9:45 PM, Ali Çehreli wrote:

>

On 12/13/22 18:05, H. S. Teoh wrote:

>

Hmm.  Whatever happened to that proposal for GC-less exceptions?
Something about allocating the exception from a static buffer and
freeing it in the catch block or something?

I have an errornogc module here:

  https://code.dlang.org/packages/alid

I hope it still compiles. :)

FYI, throwing actually uses the GC unless you override the traceinfo allocator. Yes, even if it's marked @nogc (functions marked @nogc can still call arbitrary C functions that might allocate using the GC).

Hmm, I'm experimenting with the following code for errors handling in my small @nogc compatible dub package:

@safe @nogc:

/* @nogc compatible replacement for enforce */
T enforce(string msg, T)(T cond)
{
    if (!cond)
    {
        static immutable e = new Exception(msg);
        throw e;
    }
    return cond;
}

void main()
{
    try
    {
        enforce!"trigger exception by a comparison error"(1 == 2);
    }
    catch (Exception e)
    {
        assert(e.msg == "trigger exception by a comparison error");
    }
    enforce!"and now again without try/catch"(1 == 2);
}

Does it also GC allocate behind the scene? Are there any other possible problems with it?

December 15, 2022

On Thursday, 15 December 2022 at 11:21:56 UTC, IGotD- wrote:

>

On Thursday, 15 December 2022 at 08:42:22 UTC, ikod wrote:

>

Probably this is common case when your program works in tight loop - like game, or webserver under high load. Process just have no spare time to handle GC cleanups (for stop-the-world collectors).

One interesting observation here in the forum and also in articles, blogs etc about the D garbage collector about how you can speed up memory management. All those ideas and tricks are based on that you in some way should avoid or circumvent the garbage collector. Then the question is, how good is a computer algorithm if you are supposed to avoid it all the time?

Also, it doesn't matter if "the GC stop world" duration are very short. It takes time for the OS scheduler to stop all thread which probably is a significant part of the GC pause. Then depending on the load the is also a duration until the thread is started again.

Read the following algorithm:

auto myArray = [1, 9, 5, 20, 30];
foreach(value; myArray)
{
    myArray.sort();
    writeln(value);
}

This is such misuse. Array sorting is a real heavy task that you must avoid all the time, and when you do it, you will want to cache its result. It is the same thing that happens with GC.

I use GC carelessly on initialization, but after I'm running my game loop, I totally avoid all kind of allocations. In a game for example, I'm using a text display which needs to concatenate strings and show its result: There is 2 ways to do it:

1: Will it need change? Then I use my @nogc String.
2: Does it happen only at initialization? Use string as anyone would do.

Even then, this is not that important, I have coded a lot of games in Javascript and the GC never made my game slow. In Javascript it is actually impossible to run from GC. The only reason I'm doing that is for not making my engine contribute to user code GC feeding.