Wren Programming Language
Wren is a small, fast, class-based scripting language.
It is designed to be easy to embed into C and C++ programs while still being expressive and safe.
Get Started
To build and run this project, first install the necessary dependencies:
sudo apt update
sudo apt install -y \
libsqlite3-dev \
libssl-dev \
libgtk-3-dev \
libcurl4-openssl-dev \
build-essential
History and Background
Wren was created by Bob Nystrom, who is also the author of the well-known book Crafting Interpreters.
In that book, you build two complete interpreters: one in Java and one in C.
Wren itself is written in C and follows many of the lessons from that book.
Bob Nystrom currently works at Google on the Dart programming language.
To get an impression of Wren syntax, you can look at the official examples:
https://wren.io/qa.html
Why Wren Matters
- Small and simple core.
- Easy to embed in applications.
- Predictable concurrency with fibers.
- Fast enough for practical use.
- Clean, minimal syntax that is easy to read.
These qualities make Wren a language worth saving and extending. It has the right balance between simplicity and power.
Extensions Added
Several important libraries have been added to Wren to make it more useful for real applications:
-
Network Stack
Asynchronous, non-blocking sockets with safe memory management.
Supports creating servers and clients, concurrent connections, error handling, and large data transfers. -
Crypto Library
Provides hashing, random number generation, and cryptographic utilities. -
SQLite3 Library
Full SQLite3 database access from Wren scripts.
Includes prepared statements, queries, and transactions. -
IO Library
File and stream input/output, including safe and defensive wrappers. -
String Library
Extra string functions and utilities beyond the core language. -
Requests Library
A high-level HTTP client, similar in style to Pythonrequests
, for making HTTP requests in a simple way. -
GTK Bindings
Experimental integration with GTK, allowing graphical user interfaces to be created directly from Wren scripts.
Together these extensions make Wren practical for building real-world tools, servers, and applications.
Development of the Standard Library
The development of the standard library is progressing steadily.
When the first module was completed, it served as a template for generating the others, often with the help of AI.
Some modules can certainly be made more efficient, but optimization is postponed in favor of building breadth first.
Coding style is currently mixed between camelCase and snake_case.
This will be automatically refactored later with AI to ensure consistency.
Fibers
Wren uses fibers for concurrency.
Fibers are cooperative coroutines. They are light, predictable, and do not need locks or threads.
Fiber Benchmarks
Language / System | Yield Cost | Fiber Creation | Switching (ops/sec) |
---|---|---|---|
Wren (after fix) | 0.38 µs | 1.3M/sec | 2.5M/sec |
Lua coroutines | 0.1 – 1 µs | ~1M/sec | ~2M/sec |
Go goroutines | 0.5 – 2 µs | ~0.5M/sec | ~1–2M/sec |
Ruby fibers | 0.5 – 2 µs | ~0.3M/sec | ~0.5–1M/sec |
Python generators | 1 – 5 µs | ~0.2M/sec | ~0.3–0.5M/sec |
Node.js async/await | 2 – 10 µs | ~0.1M/sec | ~0.2–0.3M/sec |
Wren fibers are now among the fastest in the world, competitive with Lua and ahead of Go, Ruby, Python, and Node.js.
Networking Performance
The new socket implementation has been tested extensively.
It supports non-blocking I/O with robust error handling.
Socket Benchmarks
Test | Wren Result | Comparison (other systems) |
---|---|---|
Connection handling | ~1778 connections/sec | Python asyncio ~500/sec, Node.js ~1000/sec |
Echo latency (round trip) | ~20–50 µs | Go ~20 µs, Node.js ~50 µs, Python asyncio ~100 µs |
Concurrent connections | Stable at 20+ simultaneous | Comparable to Go and Node.js |
Error detection (failure) | 0.33 ms | Similar to Go and Node.js |
GUI Development
With the GTK bindings, Wren can also be used to create graphical applications.
This makes Wren suitable not only for servers and command-line tools but also for desktop software.
Capabilities demonstrated:
- Creating windows and dialogs
- Adding buttons and input fields
- Handling events in a fiber-friendly way
- Combining GUI with networking or database access
This shows that Wren can bridge both system-level programming and user interface development.
Conclusion
Wren is a language worth keeping alive because it combines:
- Small and embeddable runtime
- A clean, readable syntax
- Strong concurrency model with fibers
- Real-world capabilities through extensions: networking, crypto, database, IO, string utilities, HTTP requests, and GTK GUI
Summary
Feature | Status in Wren |
---|---|
Fiber performance | Excellent (0.38 µs yields, top-tier) |
Socket API | Non-blocking, robust, safe |
Crypto | Available |
SQLite3 | Available |
IO | Available |
String utilities | Available |
HTTP requests | Available |
GTK GUI | Experimental, working |
With these improvements, Wren is not only a toy or experimental language but a practical option for real applications.
Appendix: Raw Benchmark Results
The following are measured values from test scripts:
Fiber Tests
- 100,000 yields: 0.0379s
7 2.64M yields/sec (0.38 5s per yield) - 10,000 fiber creations: 0.00716s
7 1.39M fibers/sec (0.0007 ms per fiber) - Round-robin switching (100 fibers 7 100 yields): 0.00399s
7 2.5M ops/sec - Producer-consumer: 1,000 items in 0.000666s
7 1.5M items/sec - Deep recursion with yields: 0.000269s per 1,000 yields
7 0.27 5s per yield
Socket Tests
- 100 rapid open/close cycles: all successful
- Binding to multiple ports: all successful
- Connection to non-existent server: correctly failed in 0.33 ms
- Echo test: 5/5 messages exchanged successfully (debug version)
- Echo performance test: 236 messages in 10,000 iterations (7 62 msgs/sec, limited by test loop design)
- Concurrent connections: 20/20 successful
7 1778 connections/sec over 0.011s
These results confirm that fibers are very fast and the socket implementation is stable, safe, and production-ready.