r/Compilers • • 3h ago

Is it inevitable for all mature languages to move to LLVM or write their own backend?

7 Upvotes

For a month I have been writing a compiler for my own language. I started testing it from last few days to port C programs like Puff.c and JSMN. It's closed source, and being honest: it's miserably slow. The basic idea was a Go-Rust like ARC with contracts. I broadly understand that you can only take three ways:

  1. LLVM backend
  2. Clang which is LLVM's optimizer, but C is the ceiling: This is my case.
  3. Write your own backend: A task too big to even entertain at prototype level.

Only language which takes the second route, and comes out as fast is Nim, but I am not sure how it works under hood. They are also developing Nimony(worth a look) to take a new approach before Nim 3.0


r/Compilers • • 4h ago

i wrote my own programming language

Thumbnail github.com
5 Upvotes

Ribbath

Ribbath is a Rust-native web framework for file-based routing, server-rendered .rib templates, and static exports. darkrib is its component kit, with light and dark themes and self-hosted Montserrat.

Live demos: native framework demo (this repository, deployed from the static export) · legacy JavaScript toolchain example

I’m still new to this journey—it’s my first experience—and I really hope it goes as I’ve envisioned. I’d be so happy if you could star the project on GitHub. Thanks!


r/Compilers • • 1h ago

BIPLAN - An interpreter and its compiler in 24KB

Thumbnail github.com
2 Upvotes

The development of BIPLAN started in 2017. I wrote both the compiler and the interpreter from scratch avoiding external libraries, frameworks and the influence of compiler and interpreter design studies, learning by doing and evaluating results. In 9 years of experiments I wrote BCC, a pre-processor and a multi-pass compiler capable of syntax and lexical analysis (701 lines of code), and BIPLAN, a register-based virtual machine implemented with a recursive descent parser (874 lines of code).

What do you think about it?


r/Compilers • • 12h ago

New MIT-Licensed Ramanujan interpreter beating CPython: performance matrix

0 Upvotes

Motivation

Ramanujan is built as the execution runtime for a distributed volunteer computing platform[Ramanujan-Computing]. In traditional volunteer computing projects, researchers have to cross-compile and ship platform-specific native binaries for every OS and architecture whenever they introduce a new problem. With Ramanujan, simulation writers simply write standard Python code once, and the lightweight runtime executes its IR deterministically across heterogeneous volunteer devices—from desktops to Android phones, smart TVs, and smart appliances where shipping CPython's full runtime overhead isn't practical

Summary

Ramanujan runs a statically typed subset of Python through a native interpreter. I wanted to see how it compares with CPython on one machine. I ran 34 CPU-only workloads, from a 42-line Mandelbrot script to a two-pass assembler, graph algorithms, and object-heavy data structures like segment trees and tries. Both engines ran the same Python source without changes.

On an Apple M3, the geometric-mean speedup was 1.92× against CPython 3.12.2 running precompiled .pyc files directly, and 1.69× with CPython's -S flag, which skips importing site. These are whole-process timings, not interpreter-loop timings: startup, loading, execution, and shutdown are included, as is Ramanujan's IR linking. Source compilation is excluded on both sides.

In a separate memory benchmark, Ramanujan had a lower median peak physical footprint on 32 of 34 workloads. Across the suite, CPython's footprint was 1.63× Ramanujan's (geometric mean of the per-workload ratios). Unlike the timing runs, the memory runs used .py source for CPython, not .pyc files.

Wall time

Median / p99 in milliseconds, from 100 interleaved fresh-process runs per workload and configuration. Ramanujan runs native X.pb <entry> 1; CPython runs python3 X.pyc or python3 -S X.pyc (-S skips importing site). Neither timing includes source compilation. Both include process startup, loading, execution, and shutdown; Ramanujan also links its IR on every run. Speedup = CPython median / Ramanujan median.

Ramanujan had a lower median on all 34 workloads against both CPython baselines.

OOP workloads (20)

Geometric-mean speedup: 2.07x vs default CPython; 1.78x vs -S.

WorkloadRamanujanCPython .pycCPython -S .pycSpeedupSpeedup vs -S
method-reuse8.29 / 10.1119.19 / 20.2616.74 / 18.802.32x2.02x
factory-return5.79 / 6.3513.16 / 16.5310.85 / 11.432.27x1.87x
polymorphic-dispatch12.87 / 15.3729.95 / 31.8227.55 / 28.862.33x2.14x
none-linked-list6.59 / 16.4714.96 / 26.6412.60 / 22.412.27x1.91x
bst-none-children9.36 / 10.1116.93 / 18.8014.58 / 15.741.81x1.56x
isinstance-dispatch13.32 / 16.8248.17 / 50.7445.81 / 47.503.61x3.44x
type-reflection10.16 / 12.6725.77 / 26.7123.43 / 24.262.54x2.31x
static-class-methods21.20 / 24.9061.60 / 63.2459.20 / 67.812.91x2.79x
abstract-interface14.97 / 24.2533.97 / 65.1831.34 / 49.562.27x2.09x
none-checks10.32 / 11.9527.62 / 33.3425.19 / 28.722.68x2.44x
linked_list4.86 / 5.749.20 / 11.056.92 / 8.571.89x1.42x
trees7.66 / 8.0511.86 / 12.569.57 / 10.321.55x1.25x
heap5.25 / 5.659.42 / 10.317.09 / 8.001.79x1.35x
graph6.24 / 7.4210.01 / 10.947.60 / 8.261.60x1.22x
lru_cache15.86 / 16.3625.23 / 26.7423.01 / 24.001.59x1.45x
expression_tree6.21 / 7.1011.07 / 12.908.80 / 10.201.78x1.42x
union_find9.79 / 10.4816.09 / 17.6613.69 / 14.801.64x1.40x
skip_list12.69 / 14.5520.05 / 21.0417.26 / 18.181.58x1.36x
trie21.48 / 28.8133.22 / 57.6530.66 / 44.271.55x1.43x
segment_tree8.78 / 10.3622.69 / 24.5420.17 / 22.362.58x2.30x

Plain workloads (14)

Geometric-mean speedup: 1.73x vs default CPython; 1.57x vs -S.

WorkloadRamanujanCPython .pycCPython -S .pycSpeedupSpeedup vs -S
assembler11.00 / 25.9819.53 / 52.5816.89 / 42.921.78x1.54x
expression_compiler24.55 / 26.2629.45 / 31.9326.93 / 28.311.20x1.10x
bignum18.24 / 36.1930.53 / 42.7228.00 / 56.171.67x1.53x
ntt19.90 / 21.7046.56 / 51.0144.22 / 49.522.34x2.22x
lz779.26 / 12.0518.36 / 23.6815.96 / 22.051.98x1.72x
sorting32.91 / 39.2947.88 / 75.6545.56 / 79.991.45x1.38x
dynamic_programming20.04 / 23.9127.50 / 29.3424.99 / 29.191.37x1.25x
graph_algorithms17.01 / 18.1328.64 / 30.1026.14 / 28.651.68x1.54x
number_theory57.82 / 61.5990.42 / 97.5886.10 / 88.211.56x1.49x
sudoku11.78 / 12.3720.87 / 21.5818.37 / 20.811.77x1.56x
nqueens8.25 / 9.0513.17 / 15.4310.75 / 13.091.60x1.30x
nbody12.66 / 27.1523.46 / 36.3220.78 / 32.061.85x1.64x
mandelbrot20.45 / 22.8948.99 / 53.0746.66 / 49.612.40x2.28x
heat_stencil24.13 / 30.9248.61 / 53.8646.15 / 48.452.01x1.91x

Peak physical footprint

Median MB from 100 interleaved fresh-process runs per workload and engine, measured with macOS /usr/bin/time -l. These are separate from the timing runs: CPython ran python3 X.py (source), and Ramanujan ran native X.pb <entry> 1. A ratio above 1 means Ramanujan used less memory.

Across all 34 workloads, the geometric mean of the CPython / Ramanujan footprint ratios was 1.63x; Ramanujan was lower on 32 of 34.

OOP workloads (20)

WorkloadRamanujan (MB)CPython (MB)CPython / Ramanujan
method-reuse1.915.342.80x
factory-return1.925.162.68x
polymorphic-dispatch1.955.202.66x
none-linked-list1.975.362.72x
bst-none-children2.505.642.26x
isinstance-dispatch2.025.142.55x
type-reflection1.975.172.63x
static-class-methods2.095.162.46x
abstract-interface2.035.142.53x
none-checks2.025.172.57x
linked_list3.725.661.52x
trees4.435.881.33x
heap4.205.621.34x
graph5.786.031.04x
lru_cache3.805.631.48x
expression_tree3.845.801.51x
union_find4.116.021.47x
skip_list3.865.951.54x
trie4.176.191.48x
segment_tree3.775.661.50x

Plain workloads (14)

WorkloadRamanujan (MB)CPython (MB)CPython / Ramanujan
assembler4.035.781.43x
expression_compiler4.695.851.25x
bignum4.345.821.34x
ntt3.895.551.43x
lz774.955.751.16x
sorting5.635.971.06x
dynamic_programming8.026.040.75x
graph_algorithms6.196.110.99x
number_theory6.206.731.09x
sudoku4.035.861.45x
nqueens2.415.412.25x
nbody3.705.611.51x
mandelbrot3.735.341.43x
heat_stencil3.165.501.74x