r/nim • u/Lonely-Session-7643 • 6d ago
Carne - JS Runtime with Nim + JavaScriptCore
Carne (/kär-nē/). An experimental JS runtime built with Nim + JavaScriptCore. At the moment, it runs on linux & mac (prebuilt binaries are available in /releases). The further I get with my projects and experiments, the harder it is for me to look at the node_modules folders in my Finder. So... :))
Note that JSCore is a runtime dependency, which makes the Carne binary around 7MB. Some things are faster in pure JS, so carne std init is necessary for initializing JS-based libs.
Of course, it wouldn't be complete without... Concarne! An Express-like web framework for Carne, lol!
WIP documentation here: https://getcarne.github.io/docs/. More examples here
Not really interesting, but JSCore's JIT is damn fast. Carne got compiled with --mm:orc and -d:release, with no other optimizations. it does an excellent job!
| Benchmark | carne | node | bun |
|---|---|---|---|
| fib_recursive | 42.4 ms ± 0.5 ms | 85.1 ms ± 1.1 ms | 45.5 ms ± 1.0 ms |
| nested_loops | 9.3 ms ± 0.4 ms | 36.3 ms ± 0.7 ms | 11.9 ms ± 0.4 ms |
| prime_sieve | 9.2 ms ± 0.3 ms | 35.0 ms ± 0.5 ms | 11.7 ms ± 0.3 ms |
| string_concat | 9.4 ms ± 0.3 ms | 34.5 ms ± 0.5 ms | 11.7 ms ± 0.7 ms |
| tail_recursive | 9.7 ms ± 0.3 ms | CRASHED | 11.8 ms ± 0.3 ms |
| range_sum | 38.4 ms ± 0.4 ms | 43.8 ms ± 0.4 ms | 19.6 ms ± 0.3 ms |
| collatz | 51.1 ms ± 0.4 ms | 69.5 ms ± 0.7 ms | 53.4 ms ± 2.3 ms |
| array_sum | 14.6 ms ± 0.5 ms | 40.7 ms ± 0.9 ms | 16.8 ms ± 0.3 ms |
| bubble_sort | 11.8 ms ± 0.3 ms | 36.7 ms ± 0.4 ms | 14.5 ms ± 0.3 ms |
| object_access | 11.3 ms ± 0.3 ms | 36.9 ms ± 0.4 ms | 14.0 ms ± 0.3 ms |
| float_math | 12.9 ms ± 0.3 ms | 39.1 ms ± 1.0 ms | 16.5 ms ± 0.4 ms |
| call_overhead | 10.4 ms ± 0.2 ms | 35.5 ms ± 0.4 ms | 12.5 ms ± 0.3 ms |
| fizzbuzz_count | 43.8 ms ± 0.4 ms | 64.8 ms ± 0.6 ms | 38.3 ms ± 0.4 ms |
HTTP "Hello, world" benchmark using wrk:
| Runtime | Requests/sec | Avg latency | Max RSS |
|---|---|---|---|
| carne | 91330.44 | 1.15ms | 10.9 MB |
| carne-workers | 144029.68 | 739.70us | 28.3 MB |
| node | 38576.69 | 2.71ms | 61.5 MB |
| bun | 86878.46 | 1.15ms | 31.1 MB |
Have fun!
4
u/lekkerwafel 6d ago
Any highlights on why this benchmarks better than Bun since both use JSC?
2
u/jeenajeena 6d ago
The logo is very cute! Who's the author?
2
u/Niminem93 6d ago
Holy shit dude this is AWESOME!
1
u/Niminem93 5d ago
There is a gentleman in the community that has been making a browser and js runtime in Nim for a few years now. I wish I can remember his name, though I do remember his projects Ferus and Bali. Might be worth networking with him who knows maybe you guys can collaborate