Skip to content

Wyn v1.8: Green Threads and Coroutines

February 2026

Note: v1.10 replaced coroutines with a real OS thread pool. The spawn/await API is unchanged, but performance characteristics differ. See the v1.10 release notes and current benchmarks for up-to-date numbers.

v1.8 is the biggest release since v1.0. The headline feature is green threads - stackful coroutines with an M:N work-stealing scheduler.

spawn/await

wyn
fn fetch(url: string) -> string {
    return Http.get(url)
}

var f1 = spawn fetch("http://api.example.com/users")
var f2 = spawn fetch("http://api.example.com/posts")
var users = await f1
var posts = await f2

Each spawn creates a coroutine with an 8MB virtual stack (only ~4-8KB physical for simple tasks). The scheduler distributes work across OS threads. I/O operations automatically yield the coroutine and resume when data is ready.

Channels

wyn
var ch = Task.channel(10)
spawn fn() {
    for i in 0..100 {
        Task.send(ch, i)
    }
}
for i in 0..100 {
    var val = Task.recv(ch)
}

Channels are buffered and coroutine-aware. Sending to a full channel yields. Receiving from an empty channel yields.

Performance

Benchmarked at the time of the v1.8 release, on Apple silicon (wyn build with clang -O2):

  • fib(35): ~120ms (today, on an Apple M3 Pro with a current release build: 41ms)
  • Sequential spawn+await: ~20 μs/op (today: ~2 μs/op)
  • Concurrent batch (100): ~15 μs/op
  • Max concurrent spawns: ~5-10K (limited by 8MB virtual per coroutine) (today: 1M spawns fit in ~84MB RSS)
  • Binary size: ~50KB

At v1.8 spawn overhead (~20μs) was slower than Go goroutines (~1μs) but faster than Python asyncio. The scheduler has been rebuilt since - see the benchmarks page for current numbers (~1.5μs per spawn+await as of v1.21.0).

I/O event loop

The runtime includes a kqueue (macOS) / epoll (Linux) event loop. When a coroutine does a blocking I/O operation, it parks itself and the scheduler picks up other work. When the I/O completes, the coroutine resumes.

Learn More

MIT License - v1.21.0