News for hackers. Stuff that matters.
Re:Why is D's garbage collection slower than GO's? by tjoff on Saturday October 29, 2022 @05:44AM (#33382500)
The GC made sense in comparison to C style memory management. But with with Swift, Rust and modern C++ the argument can be made that GC doesn't bring anything to the table.

In the beginning the biggest drawback seemed to be performance, so people have been hell-bent on fixing that for decades now. Completely ignoring that the "don't need to care about memory" mindset is flawed. You always need to think about memory, and if you do you might as well do it yourself. It doesn't take more time to do in the long run and you are forced to design a better system because of it.

For scripts it is a really nice have. But for a proper language writing large-scale applications? No thanks.

Re:Why is D's garbage collection slower than GO's? by kaba0 on Saturday October 29, 2022 @06:36AM (#33382778)
> But with with Swift, Rust and modern C++ the argument can be made that GC doesn't bring anything to the table.

Well, it would be a bad argument :D

A reference counter is arguably the slowest option, so Swift is out of the picture (besides it leaks circular dependencies). Rust is a good idea, but it is a tradeoff. Quite a lot of programs can’t be expressed with strictly tree-like lifecycles, and then you are either left with the yet again slower (A)RC, or unsafe. C++ is in pretty similar shoes. They are good for the niche they were made, systems/low-level programming.

Let me quote from the Garbage collector handbook: “above all, memory management is a software engineering issue. Well-designed programs are built from components [..] that are highly cohesive and loosely coupled. [..] modules should not have to know the rules of the memory management game played by other modules. [..] GC uncouples the problem of memory management from interfaces.”

It says nothing about not thinking about memory, you are free to optimize it where you need it.

EDIT: Oh and dynamic allocation is much faster with a modern GC than with malloc and friends, plus a moving GC can defragment heap.

Re:Why is D's garbage collection slower than GO's? by zozbot234 on Saturday October 29, 2022 @07:02AM (#33382933)
> A reference counter is arguably the slowest option, so Swift is out of the picture

It's not that simple. Obligate refcounting has lower throughput than obligate tracing GC but offsets that with more predictable latency, which might be good for the Swift use case. Rust uses a mix of stack-based allocation, manual heap allocation and RC - and the RC only needs to manage "owners" as determined via the borrowck, as opposed to ephemeral references. So is way more efficient than something like Swift ARC, where refcounting is essentially ubiquitous and any operations via references will incur slow atomic RC updates.

Re:Why is D's garbage collection slower than GO's? by kaba0 on Saturday October 29, 2022 @07:41AM (#33383155)
Well, ever seen a C++ program that seemingly finished execution, but still haven’t exited?

That’s shared pointers recursively freeing up their reference trees. There is a great paper showing that RC tracks object death, while tracing GCs track object “liveness”, so its essentially two sides of the same coin.

As for RC, sure, at compile time many of the work can be omitted, but atomic writes needed for the counters are fundamentally slow operations on modern architectures.

Re:Why is D's garbage collection slower than GO's? by saagarjha on Saturday October 29, 2022 @08:24AM (#33383453)
You can do reference counting without making it atomic, by prohibiting sharing across threads. It’s not fundamentally required. See Rust’s Rc, for example.
Re:Why is D's garbage collection slower than GO's? by germandiago on Sunday October 30, 2022 @02:44PM (#33397321)
or boost local shared ptr
Re:Why is D's garbage collection slower than GO's? by zozbot234 on Saturday October 29, 2022 @05:50AM (#33382527)
> But with with Swift, Rust and modern C++ the argument can be made that GC doesn't bring anything to the table.

GC will always be needed to solve problems dealing with general graphs containing possible cycles. Not coincidentally, this describes many of the GOFAI problems for which GC (in the context of LISP) was first developed.

Re:Why is D's garbage collection slower than GO's? by ninkendo on Saturday October 29, 2022 @08:44AM (#33383574)
I mean, what you’re saying is probably technically true for very specific problems that are contrived specifically to show shortcomings in refcounting, but in practice I’ve never seen it matter.

Weak and unowned pointers are pretty simple to deal with, and I’ve never seen a situation where it’s really confusing whether a pointer should be strong or weak in swift. Everything mostly just works, and if you need to point back to the object that owns you, it’s usually pretty clear by the abstraction you’re building that you need a weak/unowned reference to do it.

Re:Why is D's garbage collection slower than GO's? by zozbot234 on Saturday October 29, 2022 @10:10AM (#33384165)
> and if you need to point back to the object that owns you

That's not the interesting case; that is indeed easily addressed by "weak" pointers. What's interesting is the case of a spaghetti reference graph where none of the objects definitely "owns" any other, and even the choice of GC roots might be dynamic.

Re:Why is D's garbage collection slower than GO's? by ninkendo on Sunday October 30, 2022 @03:54PM (#33398004)
The specific point I’m making is that the “interesting case” is rare. Rare enough that I’ve never seen it in person.
Re:Why is D's garbage collection slower than GO's? by pjmlp on Saturday October 29, 2022 @06:21AM (#33382695)
Swift is a GC language, reference counting is a GC algorithm as per CS literature.

Modern C++ unfortunely still has too much people writing classical C with classes, to make it properly safe.

Rust, yes, affine types are great, but their usability is only justified in scenarios where having any kind of automatic memory management isn't acceptable.

Re:Why is D's garbage collection slower than GO's? by xigoi on Saturday October 29, 2022 @06:02AM (#33382594)
> But with with Swift, Rust and modern C++ the argument can be made that GC doesn't bring anything to the table.

With Rust and C++ (don't know about Swift), you still have to spend a lot of time thinking about memory.

Re:Why is D's garbage collection slower than GO's? by zozbot234 on Saturday October 29, 2022 @06:33AM (#33382759)
> With Rust and C++ (don't know about Swift), you s still have to spend a lot of time thinking about memory.

You don't think about memory, you just think about how to ensure that you're always referencing live objects. And you need that kind of thinking anyway to deal with non-memory resources, where a GC won't help you at all.

Re:Why is D's garbage collection slower than GO's? by tptacek on Saturday October 29, 2022 @03:21PM (#33387164)
"You can't garbage collect file descriptors" is a very weak argument.
Re:Why is D's garbage collection slower than GO's? by tjoff on Saturday October 29, 2022 @09:14AM (#33383770)
My argument is that you always need to think about memory - even in GC languages. Being able to not think about memory is not a feature, it is a problem.
Re:Why is D's garbage collection slower than GO's? by xigoi on Saturday October 29, 2022 @09:53AM (#33384055)
Why? It's a low-level implementation detail. Should you also always think about registers and jumps?
Re:Why is D's garbage collection slower than GO's? by tjoff on Saturday October 29, 2022 @02:04PM (#33386483)
It is absolute not a low level detail, it is a huge part of your application and cannot be ignored.
Re:Why is D's garbage collection slower than GO's? by xigoi on Saturday October 29, 2022 @02:16PM (#33386589)
Interesting, I've made many programs without caring about memory management and they worked just fine.
Re:Why is D's garbage collection slower than GO's? by lawn on Saturday October 29, 2022 @03:50PM (#33387404)
It completely depends on what application you're creating if it can be ignored or not.
Re:Why is D's garbage collection slower than GO's? by germandiago on Sunday October 30, 2022 @02:46PM (#33397336)
You can just ignore it all almost as long as you stick to RAII and keep customizing allocators where you need. It is quite reasonable bc you can start to code fast and later imprpve performance in the allocation patterns.

There are other ways such as customozong new/delete.

Re:Why is D's garbage collection slower than GO's? by xigoi on Sunday October 30, 2022 @02:55PM (#33397435)
Custom allocators definitely count as thinking about memory. Possibly also RAII.
Re:Why is D's garbage collection slower than GO's? by germandiago on Monday October 31, 2022 @05:00PM (#33413052)
True. But pauses due to a GC also counts as thinking about memory...

Depends on your situation what you can or cannot do/afford.

Re:Why is D's garbage collection slower than GO's? by amelius on Saturday October 29, 2022 @06:45AM (#33382831)
> The GC made sense in comparison to C style memory management. But with with Swift, Rust and modern C++ the argument can be made that GC doesn't bring anything to the table.

Haskell needs a GC too. You can't do ergonomic functional programming without GC (it has been attempted).

Re:Why is D's garbage collection slower than GO's? by zozbot234 on Saturday October 29, 2022 @06:52AM (#33382874)
Haskell needs a GC because it can't figure out whether a closure might outlive any of the variables it references. This can be addressed by a Rust-like borrow checker. (In the rare general case where multiple independent pieces of code need to keep some object alive, this can be done via refcounting which of course is a kind of GC.)
Re:Why is D's garbage collection slower than GO's? by amelius on Saturday October 29, 2022 @07:22AM (#33383036)
Type based memory management has been done in FP languages. The point is that it completely breaks the experience.
Re:Why is D's garbage collection slower than GO's? by efficax on Saturday October 29, 2022 @09:26PM (#33389925)
gc makes it easier to conceive of and program algorithms that use cyclical graphs, a pretty broad problem. try and implement these structures in rust and you quickly run into headaches. solveable headaches but headaches all the same. they’re trivial in a gc language