Let me, however, show you a quick demonstration of Clio, and how to do multi-threading with it. To do multi-threading on the browser or on Node.js, all you need to do is to define your functions and call them using the |sandwich| syntax, Clio takes care of the rest:
If you want to, you can run this example directly on the playground.
In this example, there are a few little details that need explanation. On line 8 of the sample code above, you can see a demonstration of the Clio sandwich syntax |fib|, which runs the fib function in a separate thread. On the same line, you can see that -> * is used for mapping the data to the|fib|function. On line 9, (console.log @it) is an anonymous function that accepts it as its first parameter.
With Clio, it is also possible to import functions over the network and use them like any other regular function. Instead of making and implementing API endpoints, with Clio you can just host your functions and import them elsewhere, Clio gives you FaaS and micro-services architecture for free, without any extra hassle. For example
is valid Clio code. To see a demonstration of the remote functions, you can check out our todo example here.
The Clio v0.11.0 release, which just got recently published brings a couple of important changes. These changes are mostly performance-related: they improve the execution speed of Clio code, as well as improving the overall RPC and multi-threading performance. In this article, I’ll be showing you how fast Clio really is, and we will go through these new enhancements together. Let’s start with the performance!
Becomes this in Clio:
Clio has a network-based parallelism model. You can call it a distributed computing model. On startup, Clio creates a central hub or message broker, called a dispatcher, and listens to connections on different protocols based on the project’s configuration. Then it spawns workers and waits for them to connect to the dispatcher. A dispatcher is just a message hub or a broker that relays messages between the main thread and the workers. There is no shared memory between the workers and the main thread, so Clio has to serialize each and every message.
Sia is a binary serialization format, and as you can see in the above chart, Sia is extremely fast! To see more benchmarks, or to learn more about Sia and how it was made so fast, you can refer to this medium article. Using Sia as a serialization library, Clio gained a big performance boost on multi-threading, its remote function calls and RPC protocol.
The above chart shows the performance gain of Clio after I made the switch to Sia. Not only it’s faster to serialize the data, it is now also faster to transfer the data. With Sia, the serialized data is much smaller than JSON and is already in binary format! On the browser also, the performance is greatly improved. For a quick demo, you can check the video below on how faster the Clio Mandelbrot example renders on Sia in comparison to JSON:
This video shows the render time for a multi-threaded Mandelbrot example written in Clio. You can check it in action here, or you can check the source code on GitHub. As you can see, the Sia version is much faster than the JSON version, and finishes almost in half the time as the JSON one!
With Clio, it’s super easy to run functions in a thread, no need to set up anything yourself, no dealing with the web workers or the worker threads, no need to implement communication protocols or synchronization, everything is already taken care of, just run clio new to scaffold a new project, write your code, then run the clio run command and you’ll get your app up and running in just a few seconds. You can check examples on the Clio examples repository.
Clio is still a very young language and it has a long way to go, it is not production-ready yet, and I’m not rushing for a stable release. I want to keep it minimal, and I want to carefully choose what goes in or what we should keep out of the language. It is designed with the cloud and micro-services in mind, and that’s where the main focus is. With Clio, I’m aiming for a general-purpose language that is usable both on and off the web, a language that is suitable for making a website, as well as crunching numbers and scientific data.
If you have any questions, leave a comment under this article, post an issue on GitHub, and if you want to talk, you’re welcome to join our public chat on Telegram!
To install you'll need Node.js (latest version) and NPM. Clio is hosted on NPM, to install it simply do
npm i -g clio
Command Line Usage
To see a list of available
clio commands and their description you can run
Clio is in active development and it's not ready for production It is in a highly experimental state, although some stable demonstrations and test programs exist, it is not recommended to use in production.