Old Quora post: D vs Go vs Rust by Andrei Alexandrescu

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jan 3 22:22:12 UTC 2018


On Wednesday, January 03, 2018 22:06:22 Mark via Digitalmars-d wrote:
> On Wednesday, 3 January 2018 at 21:43:00 UTC, Ola Fosheim Grøstad
>
> wrote:
> > There are many ways to fix this, which has been discussed to
> > death before (like thread local garbage collection), but there
> > is no real decision making going on to deal with it.  Because
> > to deal with it you should also consider semantic/types system
> > changes.
>
> I don't know much about GCs, but can you explain why that would
> be necessary?

Well, with how shared and casting works, it's not actually possible to have
thread-local GC heaps, because objects can be passed between threads.
Casting to and from shared would have to also tell the GC to change which
thread manages that object's memory, and that would be a pretty big change
to how casting works. It also wouldn't play well at all with how shared is
used, because in order to use a shared object, you either have to use
atomics (which wouldn't be a problem, since no casting is involved), or you
have to temporarily cast the object to thread-local after protecting that
section of code with a mutex to ensure that it's safe to treat that object
as thread-local within that portion of code. Changing what manages the
object's memory for that would just harm performance. Another thing to
consider is that pointers don't actually know what manages their memory.
That's not part of the type system. So, how would having casts move objects
from the thread-local GC to the shared one (or vice versa) interact with
stuff like pointers that refer to malloc-ed memory?

Seemingly simple improvements to the GC fall apart _really_ fast when you
consider how much you can legally do in D and how the type system doesn't
really have anything in it to indicate what owns or manages a block of
memory. Some of the really big GC improvements that have occurred in other
GC-managed languages were able to be done, because the languages disallowed
all kinds of stuff that a language like D or C++ considers perfectly legal
and legitimate. Improvements can certainly be made to D's GC (and some
improvements have definitely been done), but without changing how D works,
we're _really_ restricted about what type of GC we can have.

- Jonathan M Davis




More information about the Digitalmars-d mailing list