208 points · by sadiq · 6y ago · 80 comments
(I am mainly waiting for multicore but SIMD/AVX would be nice as well. Transparent parallelization of code without the programmer doing anything about it except supplying a compilation flag would be a game-changer but eh, we can dream right? After all, pure functions can be detected part of the time so I don't see why not.)
I get the vibe that the current community that's driving it forward is small, dedicated and overworked. Sad to hear that but rest assured that the community will grow once OCaml has multicore support. People will want to contribute once they can suddenly replace their Python or Go codebases with OCaml.
(I'd probably also ask to throw away the C strings and only leave the UTF-8 ones in but I am aware that the OCaml developers are very committed to backwards compatibility so likely not going to happen.)
Great work and progress! Keep it up! <3
It's not open sourced yet but will be soonish.
That being said, I'm not looking to get back to C++.
Your work is interesting though. I'd like to see things like these upstreamed in Rust.
Multicore is a very nice addition, but the fact that it is going to be coupled with an effect system is a game changer for the language as a whole.
AFAIK, this is all part of the roadmap.
[1] https://www.janestreet.com/tech-talks/effective-programming/
[0] https://github.com/ocamllabs/ocaml-effects-tutorial/blob/mas...
[0] https://github.com/MPLLang/mpl
[1] https://www.polyml.org/documentation/Reference/Threads.html
It is indeed that it is hard to retrofit parallelism on to an existing language while trying to retain backwards compatibility _and_ performance.
Backwards compatibility is tricky because there's lots of C code using the C API.
Performance is hard because OCaml users are used to well performing code, with low and predictable pause times from the GC (<10ms).
The community is small and it seems like there wasn't appetite for maintaining two distinct runtimes with very different performance characteristics.
The current implementation for multicore GC (https://github.com/ocaml-multicore/ocaml-multicore) is reasonably close to upstream in performance on single threaded code and yet will scale up to multiple threads. It requires a change to the C API though.
There's a modified multicore GC (https://github.com/ctk21/ocaml-multicore/tree/stw_minor_gc) that doesn't require the C API change and we're currently writing up a paper that contrasts the two wit a fairly substantial amount of benchmarking (https://github.com/ocamllabs/sandmark).
Happy to answer any questions.
I would expect that low pause times are easy enough (or relatively easy considering the difficult domain of GC optimization), but keeping the allocations cheap is (one of) the key constraints, no?
In multicore's case it's about keeping low pause times while also keeping allocation cheap _and_ maintaining throughput.
I am very excited to use OCaml with multicore abilities but lately I realised that I have no clue how will the initial support even look like in terms of a programming API.
EDIT: Downvoters, I'm genuinely interested in hearing from you. Did I accidentally cause offense or am I 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
Tangent: does GHC ever decide that it's cheaper to just potentially evaluate something twice than to use thunks?
That seems like an over burdensome requirement given that we are swimming in cores. A 10% loss in single core performance vs 1.2x-Nx multicore performance increase would be an adequate tradeoff.
The only other option I can think of is having two different backends, one that is entirely single threaded and doesn't incur any multicore performance penalty.
I'm familiar with the latter, but would love to learn more about OCaml.
OCaml specifically is such an obscure language you'd have a hard time explaining it to most people who are software engineers.
Who cares?
Lots of financial companies, including some serious heavy-hitters like Bloomberg, use functional languages like Haskell and Ocaml. I suppose the blockchain folks are pretty enamoured with it too.
Plenty of big companies like Twitter use Scala, which is plenty functional.
Even on the front-end side: JavaScript was directly inspired by Scheme; TypeScript was hugely inspired by languages like Ocaml and Haskell; React and Redux's inspirations fall directly out of the functional programming community.
Rust, out of Mozilla, is also a descendent of the functional programming world; its compiler was originally written in Ocaml.
Just the other day there was a conversation on here about type-system enforced optionals. Almost every "modern" language has grown these in the past decade, often including monadic combinators to help minimize boilerplate. All of this comes from what ML and Haskell were doing as many as 30 years ago.
Speaking of monadic combinators: these are also frequently used in modern languages with async libraries to avoid what the JS community termed "callback hell".
TBH if you've developed software in the past ten years, it's unlikely you haven't been hugely affected by what the FP community has been doing, and it's not impossible that watching what they're doing now give you a glimpse of where mainstream programming will be a decade or more down the line.
Apart from HN / reddit bubble, not many people know about FP, and not to imply that's their fault. FP is still weird, difficult for mere mortals, and ivory tower elitism is holding some of its useful ideas back.
Given that most HR departments still value having a degree, that is still quite a bit of people, specially if one extrapolates to other countries that share similar attitude to universities and HR hiring practices.
* Java/C# generics
* sealed interfaces and record classes
* pattern matching
* first-class functions with closures
* even type system itself (eg Python is gaining a type system)
* ...
The world of programming languages is converging, no matter how slowly, towards ML
I also like OCaml because it is both imperative and functional, so I can use the best of both paradigms.