InfoQ Homepage News OCaml 5 Will Include Multicore Support
OCaml 5 Will Include Multicore Support
This item in japanese
Oct 11, 2021 2 min read
Write for InfoQ
Feed your curiosity. Help 550k+ globalsenior developers
each month stay ahead.Get in touch
The OCaml team has announced a detailed roadmap to add multicore support to the language runtime and will focus on merging the multicore and standard runtimes in the next minor releases leading to OCaml 5.
The development of OCaml multicore has reached a point where further integration into OCaml’s main branch requires fully committing to a switch to OCaml multicore.
Multicore support stands for shared memory parallel multiprocessing, and will allow an OCaml program to use multiple threads running on different cores within the same CPU, thus leveraging their intrinsic parallelism. The OCaml community has been working on bringing symmetric multiprocessing to the language for quite a number of years, with the main roadblock being the implementation of a parallel garbage collector.
Multicore OCaml uses the concept of domains to represent the unit of parallelism, which are mapped to native threads. The low-level domain API supports the usual operations of spawn, join, wait, and notify in addition to domain-local storage and atomic memory operations with low overhead.
To make it possible to share memory across domains, Multicore OCaml implements a new garbage collector to replace the generational, non-moving, incremental, mark-and-sweep GC used in standard OCaml. The new Multicore OCaml GC uses a stop-the-world, parallel collection for minor heap (younger objects) in combination with a mostly concurrent mark-and-sweep collection for major heap (longer-lived objects, which can accumulate to GBs).
One major concern, given that millions of lines of OCaml code are run in production, and none were written with parallelism or concurrency in mind, is ensuring backward compatibility and preserving performance.
The new GC strikes a balance between performance and feature backwards compatibility for sequential programs and scales admirably on modern multicore processors.
Recent benchmarks have indeed shown the new GC to pause for 10ms on minor heap collections and for 5ms on major heap collections, providing an overall performance improvement of 1% over the classical OCaml GC.
It is important to note OCaml 5 will only include a minimal multicore runtime system and will not include at first stable user-facing concurrency and parallelism libraries. At this respect, extensive experimentation has been carried through which led to the DomainsLib API, which offers a number of proven abstractions on top of the Domain API, including the notion of Task
and Task
pools, async/await, parallel for, and so on. Still, according to OCaml maintainers, "some work remains to offer long-term, user-facing concurrent and parallel programming abstractions", so those abstractions will not make it into OCaml 5.
In addition to shared memory programming, Multicore OCaml will also bring improvements to concurrency programming through the introduction of effect handlers, which provide the foundation for non-local control flow to enable generators, lightweight threads, coroutines, and other abstractions.
Multicore will become standard in OCaml's next major release, OCaml 5, which should ship between March and April 2022. Nevertheless, you can already use Multicore OCaml by building it or installing it using OPAM.
This content is in the Programming Languages topic
Related Topics:
-
Related Editorial
-
Related Sponsors
-
Popular across InfoQ
-
AWS Introduces ECS Managed Instances for Containerized Applications
-
Producing a Better Software Architecture with Residuality Theory
-
GitHub Introduces New Embedding Model to Improve Code Search and Context
-
Google DeepMind Introduces CodeMender, an AI Agent for Automated Code Repair
-
Building Distributed Event-Driven Architectures across Multi-Cloud Boundaries
-
Elena Samuylova on Large Language Model (LLM)-Based Application Evaluation and LLM as a Judge
-
Related Content
The InfoQ Newsletter
A round-up of last week’s content on InfoQ sent out every Tuesday. Join a community of over 250,000 senior developers. View an example