News for hackers. Stuff that matters.
Re:Multicore OCaml: Feb 2020 update by throwaway894345 on Friday February 28, 2020 @12:07PM (#22444246)
It's hard to make a concurrent GC that also allows for the kind of super-cheap allocation that OCaml depends on for its performance characteristics. Allocation is expensive in Go, for example, but this is okay because Go has value semantics and an imperative model (no need to allocate memory on every little operation). Not sure how Haskell's GC works, but I'm guessing it more or less depends on Haskell's immutability guarantees.

EDIT: Downvoters, I'm genuinely interested in hearing from you. Did I accidentally cause offense or am I mistaken?

Re:Multicore OCaml: Feb 2020 update by kccqzy on Friday February 28, 2020 @03:09PM (#22445885)
I didn't downvote you, but you are mistaken.

I don't know about Go GC but your comment about Haskell is very off.

> Not sure how Haskell's GC works, but I'm guessing it more or less depends on Haskell's immutability guarantees.

This is false. Just because you see immutability on the surface doesn't mean the GC still sees a lot of immutability.

Several reasons. The first is that even pure code can depend on interior mutability in a safe way using the ST monad, or in an unsafe way using the IO monad. (The GC can't just say, I give up when a user uses an unsafe function.) You might think that interior mutability is rarely used, but that'd still be wrong. Even something as commonplace as a hash map (from unordered-containers) uses interior mutability under the hood. Just read the source code and you'll see it. Here: http://hackage.haskell.org/package/unordered-containers-0.2.... Just grep for runST.

The bigger problem is laziness. How is laziness implemented? A value is represented as an unevaluated thunk, a closure to compute the value. When the value is needed, the closure is run and then replaced by the resulting data. This is mutability. And this is something that almost every Haskell program relies on.

I've explained this many times on HN. See eg https://news.ycombinator.com/item?id=21674749

Re:Multicore OCaml: Feb 2020 update by __s on Friday February 28, 2020 @03:51PM (#22446248)
It isn't entirely false. Haskell's GC can take some shortcuts when dealing with immutable objects as they can't reference objects older than themselves, including referencing themselves
Re:Multicore OCaml: Feb 2020 update by kccqzy on Friday February 28, 2020 @08:14PM (#22447937)
If objects can't reference themselves, do you think recursion is impossible in Haskell?

    powersOf2 = 0 : scanl (+) 1 (tail powersOf2)

    fibonacci = 0 : scanl (+) 1 fibonacci
As I have already explained, immutable objects in Haskell often use laziness. And laziness requires mutability.
Re:Multicore OCaml: Feb 2020 update by hope-striker on Friday February 28, 2020 @05:29PM (#22447009)
Really? I have no experience with Haskell's internals, but self-referential objects are fairly common in Haskell thanks to its non-strictness. The simplest one is probably the list with one element repeated forever.

    ones = 1:ones
Re:Multicore OCaml: Feb 2020 update by __s on Saturday February 29, 2020 @10:26AM (#22450990)
I'm an idiot. I meant that objects can't reference objects newer than themselves
Re:Multicore OCaml: Feb 2020 update by hope-striker on Saturday February 29, 2020 @09:12AM (#22450627)
> The bigger problem is laziness. How is laziness implemented? A value is represented as an unevaluated thunk, a closure to compute the value. When the value is needed, the closure is run and then replaced by the resulting data. This is mutability. And this is something that almost every Haskell program relies on.

Tangent: does GHC ever decide that it's cheaper to just potentially evaluate something twice than to use thunks?

Re:Multicore OCaml: Feb 2020 update by throwaway894345 on Friday February 28, 2020 @04:05PM (#22446353)
Ah, thanks for correcting me. Like I said, I am unfamiliar.
Re:Multicore OCaml: Feb 2020 update by gpderetta on Friday February 28, 2020 @12:35PM (#22444505)
Java does have cheap allocations and a (many?) scalable multithread friendly GCs though. I guess they did require many many man hours to implement and count as hard?
Re:Multicore OCaml: Feb 2020 update by throwaway894345 on Friday February 28, 2020 @12:43PM (#22444589)
Java's GC is an impressive piece of engineering with a whole lot of investment, and even then (at least until very recently) it came at the cost of high stop-the-world pause times.
Re:Multicore OCaml: Feb 2020 update by pjmlp on Friday February 28, 2020 @02:35PM (#22445616)
It wasn't recently if you were willing to shell out the bucks.

Aonix, PTC, Aicas, IBM have been selling real time JVMs for embedded OSes and bare metal deployments for quite several years, before Azul came into the picture with their pause-less GC for multi-GB heaps (which still does minimal pauses anyway).

So recently is more the addition of Azul's ideas into Shenandoah, ZGC in OpenJDK, and Metronome in OpenJ9 as free beer GC for the Java community.

Re:Multicore OCaml: Feb 2020 update by dnautics on Friday February 28, 2020 @04:58PM (#22446801)
Erlang's gc is excellent and very much concurrent, but depends on architectural assumptions you don't get on other languages.
Re:Multicore OCaml: Feb 2020 update by jeremyjh on Friday February 28, 2020 @05:43PM (#22447102)
Erlang doesn't really have concurrent gc, instead it uses shared nothing heaps and copies values everytime a process sends a message to another process.
Re:Multicore OCaml: Feb 2020 update by dnautics on Friday February 28, 2020 @08:40PM (#22448087)
and all of those copies have to be garbage collected, concurrently to the operations being run. Memory isn't infinite on long-lived servers.
Re:Multicore OCaml: Feb 2020 update by jeremyjh on Saturday February 29, 2020 @05:05PM (#22453490)
No, there is no concurrent garbage collection happening. When a process is running user code, it is not being garbage collected and vice versa. It happens at an individual process level, but the process is definitely paused while its heap is collected. It has similar benefits to concurrent garbage collection such as the fact that there is never a stop-the-world-pause, and short pauses (since the heaps are typically very small), but it is not the same and means different trade-offs and tuning may be required at the extremes.
Re:Multicore OCaml: Feb 2020 update by dnautics on Sunday March 01, 2020 @01:57PM (#22458458)
> When a process is running user code, it is not being garbage collected and vice versa

That doesn't make it 'not a garbage collector' and it also doesn't make it 'not concurrent'.

> tuning may be required at the extremes

that is very rare, and if that is disqualifying for a concurrent GC, then Java is disqualified as a concurrent GC.

Re:Multicore OCaml: Feb 2020 update by jeremyjh on Sunday March 01, 2020 @02:00PM (#22458485)
It is not "qualified" because the process using a heap is paused while the heap is collected. In a concurrent GC, nothing is paused.
Re:Multicore OCaml: Feb 2020 update by dnautics on Sunday March 01, 2020 @02:02PM (#22458498)
that's a silly distinction, because if you are running multiple threads on a single CPU, or even multiple threads on multiple CPUs, in most situations, then you're simply pushing the 'pausing' down to the hardware/os which is doing the preemption.
Re:Multicore OCaml: Feb 2020 update by jeremyjh on Sunday March 01, 2020 @02:34PM (#22458725)
Thread preemption has nothing to do with garbage collection pauses. An Erlang process that allocates a lot will spend more time being paused, irrespective of its priority which might otherwise let it run uninterrupted. I'm not going to continue this "argument" further.