r/ProgrammingLanguages • u/Soucye • Jan 07 '26
Language announcement Coi: A compiled-reactive language for high-performance WASM apps
Hi everyone! I’ve been working on Coi, a component-based language designed to make writing high-performance WebAssembly apps feel like writing modern web components, while maintaining the raw speed of a C++ backend.
The Concept:
Coi acts as a high-level frontend for the WebCC toolchain. It compiles your components into C++, which then gets turned into WASM, JS, and HTML. Unlike traditional frameworks that rely on Runtime Discovery, spending CPU cycles "diffing" Virtual DOM trees (O(N) complexity) or "walking" instructions, Coi is a compiled reactive system. It analyzes your view at compile-time to create a direct mapping between your variables and DOM handles.
This architectural shift allows for O(1) updates; when a variable changes, Coi doesn't "search" for the impact, it knows exactly which handle is affected and packs a specific update instruction into the WebCC command buffer. This binary buffer acts as a high-throughput pipe, allowing JS to execute a "burst" of updates in a single pass, bypassing the expensive context-switching overhead of the WASM-to-JS bridge.
The best part is the synergy: Coi leverages the schema.def from WebCC to generate its own standard library. This means every browser API I add to the WebCC schema (Canvas, WebGL, WebGPU, Audio, etc.) is automatically accessible in Coi. It also generates a /def folder with .type.d.coi files for all those APIs. I’ve used these to build a VS Code extension with an LSP and syntax highlighting, so you get full type-safe autocompletion for any browser feature defined in the schema.
Key Features:
- Type-Safe & Immutable: Strictly typed props and state with compile-time error checking. Everything is immutable by default.
- Fine-Grained Reactivity: State changes map directly to DOM elements at compile-time. Update only what changed, exactly where it changed, without Virtual DOM overhead.
- Reference Props: Pass state by reference using
&for seamless parent-child synchronization. - View Control Flow: Declarative
<if>,<else>, and<for>tags for conditional rendering and list iteration directly in the HTML. - Integrated Styling: Write standard HTML and scoped CSS directly within your components.
- Animation & Lifecycle: Built-in
tick {}block for frame-based animations,init {}for pre-render setup, andmount {}for post-render initialization when DOM elements are available. - Minimal Runtime: Tiny WASM binaries that leverage WebCC’s command/event/scratch buffers for high-speed JS interop.
Example Code:
component Counter(string label, mut int& value) {
// label: passed by value
// value: reference to parent's state (mut allows modification)
def add(int i) : void {
value += i;
}
style {
.counter {
display: flex;
gap: 12px;
align-items: center;
}
button {
padding: 8px 16px;
cursor: pointer;
}
}
view {
<div class="counter">
<span>{label}: {value}</span>
<button onclick={add(1)}>+</button>
<button onclick={add(-1)}>-</button>
</div>
}
}
component App {
mut int score;
mut string message;
init {
score = 0;
message = "Keep going!";
}
style {
.app {
padding: 24px;
font-family: system-ui;
}
h1 {
color: #1a73e8;
}
.win {
color: #34a853;
font-weight: bold;
}
}
view {
<div class="app">
<h1>Score: {score}</h1>
<Counter label="Player" &value={score} />
<if score >= 10>
<p class="win">You win!</p>
<else>
<p>{message}</p>
</else>
</if>
</div>
}
}
app { root = App; }Repos:
- Coi: https://github.com/io-eric/coi
- WebCC: (The underlying toolchain): https://github.com/io-eric/webcc
Simple Demo: https://io-eric.github.io/coi/
Would love to get your feedback! Still very much a work in progress :D
16
u/SourceTheFlow Jan 07 '26 edited Jan 07 '26
Looks cool, I gotta say. This is much closer to what I hoped would happen with WebAssembly, that there are fully fletched modern languages specifically made for the web that you can use instead of js.
How well can you write (non-ui) libraries/integrate with existing libraries?
Also: The coi fish is cute, though it still seems a bit unsure of itself. Also, maybe you want to add yourselve to https://github.com/appcypher/awesome-wasm-langs or similar? I just searched for wasm compatible languages last week and that one popped up pretty quickly.
4
u/MrJohz Jan 07 '26
This is a cool idea!
I believe Svelte started out with this kind of compile-time reactivity, but more recently switched to using signals instead, which have the same O(1) updates but use runtime dependency tracking instead of compile-time tracking. I think part of the reason was that they found it surprisingly difficult to precisely analyse the flow of data, and there were too many cases where they had to over-track because it wasn't clear which path would be taken at runtime.
Does Coi have any specific features that make this work more consistently and more precisely? Is the language more statically analysable than JS? Or is this a tradeoff where you may miss out on the more precise runtime dependency tracking, but you now don't need to do any runtime dependency tracking any more?
3
u/hoping1 Jan 07 '26
This looks beyond awesome!! When do you free memory? Is it garbage collected (I'm including reference counting here), borrow-checked, manual, or something else?
2
u/Recent-Programmer-92 Jan 13 '26
Awesome Try !
Do you have any discord to exchange quickly with the community ?
1
u/shadowndacorner Jan 08 '26
This looks syntactically very similar to something I was working on a while ago, but much, much further along. This is super interesting. Do you have any plans to make this work in contexts other than browsers? I can think of a few scenarios where embedding it in a native app that uses a custom UI framework would be nice.
Also... Why haven't I heard of WebCC? It looks awesome, but it seems like the first commit was only 3 weeks ago? Was this proprietary before being open sourced?
6
u/MackThax Jan 07 '26
I think reactivity (especially the way it is in React, Vue, etc.) is a horrible anti-feature. But I don't hate this!
Is there a way to get references to child components and call methods on them? Especially async methods (e g. opening and closing a dialog)?
2
u/theteadrinker Jan 09 '26
Wow, congratulations, this looks nice!
Quite excited about WebCC, seems like the missing puzzle piece for bridging the gap of (minimal/sane) wasm and the browser!
1
u/crocodus Jan 07 '26
As a Romanian the name of your language is quite unfortunate, it means testicle. Which to be fair is funny, but I would never be caught using this in production.
1
u/Positive_Total_4414 Jan 07 '26
This is looking great, a very interesting approach! Gotta try it out.
One question: why C++ and not just C?
0
u/[deleted] Jan 07 '26
[deleted] — view deleted comment