4 ms·
How's the performance of OCaml, and what's its concurrency story? I feel like on paper, at least, OCaml ticks all the boxes on my programming language wishlist
by losvedir 8y ago
How's the performance of OCaml, and what's its concurrency story?
I feel like on paper, at least, OCaml ticks all the boxes on my programming language wishlist: non-nullability, ADTs, type inference, compiles to binary. A lot like rust but a little higher level. But I've never really had a go at it. I'm sort of reluctant to sink time in it if there's not a future, but it seems to be kind of chugging along, not really gaining or losing ground, AFAICT.
- HumanDrivenDev 8y agoAs a language, it's great. As a real world environment/eco-system to get stuff soon? I've been waiting for it to get there for years, and it still hasn't. I check in every 12 months or so, am reminded how nice the language is, and quickly abandon ship when I realise how annoying it is to actually develop software.
- deleted 8y ago[deleted]
- chrisseaton 8y ago> what's its concurrency story I think concurrency is fine (threads and async are options) but parallelism still seems to always be just around the corner and never actually here. I understand part of the problem is making their GC able to handle parallel allocations without hurting basic allocation performance more than they're willing to do.
- klibertp 8y agoThe concurrency story is similar to what you get in Python. On one hand, you have event loop implementations with various conveniences for scheduling callbacks (Async, LWT); on the other, you have OS-level threads, but the runtime system has a global lock which makes only one thread execute at a given time. So no parallelism without forking[1] to separate processes. Moreover, the interactions between an event loop and OS-level threads which sometimes arise are non-trivial and in my experience very hard to get right, even with the helpers in Async. Single-threaded performance is generally good when natively compiled. In a benchmark I did a few years back, which consisted of traversing the filesystem with `opendir`, `readdir` and friends, OCaml was minimally slower than C++ and Nim (when compiled natively) and around Python and Racket when byte-compiled. It probably would be even faster if I used its imperative features. Looking at the code today I also see some unnecessary copying of lists, which could be mitigated. All in all, I think OCaml has a really good performance considering its high-level semantics. You have to be aware of relative costs of operations, but if you do, "as fast as C" is certainly attainable. OCaml code for the benchmark: https://klibert.pl/posts/walkfiles-ocaml.html https://klibert.pl/posts/walkfiles-ocaml.html and the results: https://klibert.pl/statics/images/walkfiled_perf_test1.png https://klibert.pl/statics/images/walkfiled_perf_test1.png [1] Actually, I just checked and it looks that `fork` is not implemented, so copy-on-write memory sharing is impossible, even on POSIX systems. Docs: http://caml.inria.fr/pub/docs/manual-ocaml/libunix.html http://caml.inria.fr/pub/docs/manual-ocaml/libunix.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html
- gmfawcett 8y agoRe-read the page that you linked. Fork isn't implemented on Windows, where fork doesn't exist anyways. Forking works just fine in Ocaml (on Unixes). Unix module docs (with fork!): http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html