
We're Moving Ocsigen from Lwt to Eio!

Communications Officer
Among the big changes that came with OCaml 5, concurrency via effect handlers was introduced alongside the I/O library Eio, letting users take advantage of effects to write more efficient concurrent programs. In an exciting new project, we are transitioning one of the biggest OCaml open source projects, Ocsigen, from Lwt
concurrency to concurrency using effects.
The most exciting part of this project is that we will develop tools to automate parts of the transition and document how we achieve it, which will be great resources for the wider OCaml community. This work is made possible thanks to a grant from the NLnet Foundation, which funds research and development projects furthering internet technologies and the open internet, and the NGI Zero Core fund of the European commission. This post will give you an overview of the tools, the goals of the project, and some of the methods we will use.
Why Ocsigen and Why Eio?
Ocsigen is a web and mobile framework composed of several projects and libraries including Eliom, Js_of_ocaml, Ocsigen Server, and Lwt. Ocsigen lets you build a variety of applications, from simple server-side web sites to complex client-server web and mobile apps. It is built using OCaml and benefits from its strong type system to reduce development time, simplify refactoring, and reduce the likelihood of bugs. It is one of the biggest open source projects in OCaml, and is used commercially to run the BeSport app.
Choosing a large and established project like Ocsigen will give the community a well-documented proof-of-concept of what the transition between different concurrency models looks like.
Lwt, a monadic-style concurrent programming library for OCaml, is developed as part of the Ocsigen umbrella. It has served as a way of managing I/O operations using promises for many different OCaml projects, and it is significant that Lwt’s own inventor and biggest user Ocsigen is now making the switch to effects.
The monadic style has several advantages over more traditional concurrency models (like preemptive threading or interaction loops) including fewer data races and straightforward writing, but also comes with drawbacks in comparison to direct-style effects-based concurrency. Namely, creating an abundance of heap allocations and introducing the function colouring problem to the user’s programs. With direct-style concurrency it is possible to write code in a natural, direct, style as opposed to callback-style with considerations for which code is concurrent and which is not. For more information about concurrency using effect handlers, check out our blog post on Eio.
Switching to effects is also a first step towards enabling the use of multicore features, which is not fully possible with Lwt.
Goals of the Project
The aim of the project is to create a straight-forward path for developers who want to transition projects to OCaml 5 and its new direct-style concurrency libraries. To this end, the team will develop tools for rewriting monadic syntax into direct style, rewrite interfaces, and automate the use of libraries like picos-lwt and eio-lwt. They will also develop heuristics for detecting places in the code where manual intervention is required, simplifying the developer workflow.
Put simply, we are going to:
- Automate the aspects of transforming monadic style concurrency to direct style concurrency that we can,
- Make manual intervention as smooth as possible,
- Document the process so that it is easy to replicate, troubleshoot, and adapt for other projects.
Making effects-based concurrency easier to adopt means that more OCaml developers can potentially take advantage of its benefits. Speaking from experience, Simon Grondin summed up his experiments with Eio in our interview with him from 2024:
Eio helped me reason about my code, and I discovered bugs and problems because of how much Eio had cleaned up the code. I uncovered hidden bugs in every program I converted from Lwt to Eio. Every single one also ended up being faster, not because Eio itself was faster (it was as fast as Lwt), but because of the optimisations I could now afford to make, thanks to the reduced complexity.
This project will enable more people to try Eio and see if their experience matches Simon’s, with the potential to significantly improve their workflow!
Challenges and Methods
One of the biggest challenges facing this work is the way that in an effect-based library there is an explicit fork feature to create a new thread, whereas forking is implicit with Lwt
which makes it hard to detect. This fact alone is the reason why the team won’t be able to write a fully automated conversion tool.
Another challenge for the team is to make sure that they stay as neutral as possible in their approach to the effect library's design, in order to be able to make changes later or provide multiple alternatives.
Finally, they will strive to maintain backward compatibility to the greatest extent, by using Lwt-effect bridges to enable intercompatibility for existing applications without forcing them to switch immediately.
Until Next Time
Keep your eye on our blog and OCaml Discuss for more updates on this project and the tools that emerge from it.
Connect with Tarides online on Bluesky, Mastodon, Threads, and LinkedIn or sign up for our mailing list to stay updated on our latest projects.
Open-Source Development
Tarides champions open-source development. We create and maintain key features of the OCaml language in collaboration with the OCaml community. To learn more about how you can support our open-source work, discover our page on GitHub.
Stay Updated on OCaml and MirageOS!
Subscribe to our mailing list to receive the latest news from Tarides.
By signing up, you agree to receive emails from Tarides. You can unsubscribe at any time.