r/Compilers • • 1d ago

New MIT-Licensed Ramanujan interpreter beating CPython: performance matrix

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
0 Upvotes

14 comments sorted by

4

u/Axman6 1d ago

Is it slop, or does at least one human actually understand it?

-6

u/ramanujan-computing 1d ago

u/Axman6 , what part is not clear. Kindly suggest. As far as interpreter is concerned, its not a slop. Has been hand-written [ofcourse modern LLMs have helped in writing code]. Its a robust interpreter.

Check https://gitlab.com/ramanujan-computing/Ramanujan/-/blob/main/docs/python-support.md for more details.

6

u/realestLink 1d ago

"has been hand-written" and "of course modern LLMs have helped in writing code" seem like contradictory statements?

-7

u/ramanujan-computing 1d ago

writing code is mechanical and can be deferred to LLM. Major thing that needs human is:
* to make technical decision on what can help perf

* do cpu, mem profiling, understand where cost can be saved

* review the code written by LLM is good and performant.

6

u/realestLink 1d ago

Writing code is not mechanical. I hate this fake distinction that "implementation was always trivial, the hard part was always X"

-2

u/ramanujan-computing 1d ago

That's an interesting take. Genuinely curious: once you've already locked down the memory layout, AST parsing, IR conversion and interpretation design, and C++ class design, what part of translating that spec into C++ still feels non-mechanical to you?

3

u/realestLink 1d ago

I do not see design and implementation as separate. The implementation informs the design and vice-versa. If anything, writing code is the ultimate design, where you have to specify in detail. But I think it's often the case that you do not realize the value of an abstraction or get a motivated example until you have to deal with implementation. The friction is not a tiresome constraint to be bypassed, but is a feedback signal to inform your virtue of laziness. Just as a plot or story is just an idea until you actually put pen to page. There's also myriads of micro-decisions to be made in implementation that are not mechanical at all: from naming, to micro-optimizations, to code style/preference, etc.

None of that is contained in only the memory layout or class design (if using OOP). I also don't think it makes sense to a priori decide those two things in particular

You also genuinely have a significantly shallower understanding of your system, its constraints, and how it works if you're just deciding some high level design ideas, having an LLM write all the code, and then merely reviewing the code and benchmarking it. There are things that matter beyond merely performance. Especially when you're talking about something like a programming language implementation

-1

u/ramanujan-computing 1d ago

Comparing C++ runtime implementation to 'putting pen to page' on a novel still feels like romanticizing the wrong part of the job. We're moving bytes across cache lines and not writing literature.

Keep enjoying the 'virtue of laziness' and agonizing over variable naming styles. The CPU only cares about instruction counts, cache misses, and branch mispredictions, and none of those require typing boilerplate by hand

5

u/realestLink 1d ago

Why even make a programming language then? You're posting in r/Compilers. Programming language are inherently tools of thought for expressing yourself in code. If you merely care about efficiency-maxxing "moving bytes" and performance and nothing else (ignoring the fact that code/software is made for humans and not just machines), a new programming language is hardly a good option lol

3

u/Discordbothost 20h ago

Add a longer-running measurement beside these whole-process timings. For example, run Mandelbrot 100 times inside each process, check the outputs match, and time that loop separately. That would show whether the speedup carries over to sustained simulation work once startup is amortized.

1

u/ramanujan-computing 18h ago edited 18h ago

Sounds good, here is the report: For each workload, each runtime ran 100 iterations in one process, repeated in 5 process execution.

WorkloadRamanujan exec (ms)CPython exec (ms)Exec speedupRamanujan process (ms)CPython process (ms)Whole-process speedupRamanujan footprint (MiB)CPython footprint (MiB)Memory saved (%)
method-reuse (200000 iterations)392.242964.4122.46x401.526978.8452.44x2.1255.42260.8
factory-return (30000 iterations)156.371382.8582.45x163.901396.5152.42x2.1255.42260.8
polymorphic-dispatch (200000 iterations)898.2332012.6922.24x905.7282030.3492.24x2.1105.45461.3
none-linked-list (5000 iterations)214.397538.3652.51x222.491553.0092.49x2.1575.45460.5
bst-none-children (20000 iterations)483.529762.9461.58x492.001777.5621.58x2.6885.71953.0
isinstance-dispatch (200000 iterations)889.0323843.8564.32x896.5353860.6734.31x2.2665.48558.7
type-reflection (200000 iterations)584.9111616.4962.76x592.3881632.5472.76x2.1725.46960.3
static-class-methods (200000 iterations)1638.1945201.3373.18x1648.6905216.7203.16x2.2825.70460.0
abstract-interface (200000 iterations)1067.7102349.2282.20x1075.8812363.6922.20x2.2355.50059.4
none-checks (300000 iterations)611.6271761.8992.88x619.5421776.9362.87x2.2355.43858.9
linked_list.py0.6811.3942.05x8.48815.7991.86x4.0166.18835.1
trees.py241.129240.0501.00x249.954254.7021.02x4.6256.31326.7
heap.py18.00125.0421.39x25.96538.9231.50x4.5006.11026.4
graph.py44.62962.4041.40x53.87677.0911.43x6.1416.5636.4
lru_cache.py1059.1381482.4021.40x1068.1421498.9791.40x4.1725.98530.3
expression_tree.py129.636176.1271.36x137.816190.4611.38x4.1105.93830.8
union_find.py458.412649.3981.42x466.955663.6891.42x4.4076.17228.6
skip_list.py773.518982.7941.27x782.225997.6051.28x4.1726.25033.2
trie.py1547.2112142.7041.38x1555.8472158.2151.39x4.4386.53232.1
segment_tree.py358.0261278.0743.57x367.1691293.2113.52x4.1886.11031.5
assembler.py502.712846.5011.68x511.326861.1511.68x4.1886.07931.1
expression_compiler.py1892.7191954.9871.03x1901.5981969.5501.04x4.8446.39124.2
bignum.py1266.0862008.1851.59x1276.1272024.3151.59x4.5326.93834.7
ntt.py1456.1713721.8412.56x1465.2413737.1962.55x4.1576.01630.9
lz77.py318.182876.9072.76x327.390892.4882.73x4.9856.53223.7
sorting.py2641.4233804.9191.44x2653.8473820.8541.44x5.7977.04717.7
dynamic_programming.py1046.4111759.1821.68x1060.8381775.3901.67x8.2976.672-24.4
graph_algorithms.py1021.3811922.3031.88x1031.3501939.5481.88x6.2506.6886.5
number_theory.py5023.8758146.3981.62x5039.7538161.8741.62x6.40710.53239.2
sudoku.py668.8641134.8341.70x677.9381149.5921.70x4.2196.11030.9
nqueens.py387.582377.2580.97x395.765391.9750.99x2.6105.54752.9
nbody.py682.4551277.7391.87x691.9361292.8751.87x3.9696.18835.9
mandelbrot.py1431.0813910.1862.73x1439.9713925.1392.73x3.9076.42239.2
heat_stencil.py1887.4283848.8922.04x1895.9203865.1742.04x3.4856.00041.9

1

u/pm-me-manifestos 15h ago

a statically typed subset of python

Why is it that every few months someone comes here thinking they're God's gift to creation by writing a compiler or interpreter for ersatz-python that's like 1.5x faster because they leave out all the hard parts about Python. We've had Nim and Cython forever at this point.

1

u/ramanujan-computing 15h ago

Nim and Cython compile down to native C binaries for a specific OS and CPU architecture—which is the exact opposite of what's needed here.

As noted in the Motivation section, Ramanujan is the execution runtime for a distributed volunteer computing platform. Researchers write a simulation once in standard Python, compile it to portable IR, and dispatch it across heterogeneous volunteer devices (desktops, Android phones, smart TVs) without cross-compiling native binaries per platform or bundling CPython's runtime footprint. Getting ~1.5× over CPython while staying portable and low-memory is a bonus, not the sole reason it exists.

Thanks for the comment u/pm-me-manifestos .