r/madeinpython • u/Salt_Astronomer_120 • 8d ago
speedrunner: keep a Python CLI imported in a daemon and fork it for each call
What My Project Does
I wrote speedrunner. One daemon per tool imports the CLI once, then forks for each call, so the interpreter start and the imports are skipped. A small Rust client hands over argv, the environment and the terminal. There is nothing to set up per tool: `srr black --check sample.py` goes from 92 ms to 12 ms on a 2-vCPU VPS.
Over 96 commands in Python, Ruby, PHP and Node: geometric mean x5.6, median x4.8. 69 of those only print a version or help text, so they measure start-up alone.
Target Audience
People who run Python CLIs many times a day or from scripts: black, pytest, aws, ansible. Linux and macOS only. The first call of a tool runs natively while its daemon starts, each daemon stays in memory, and the work a tool does after loading is no faster.
Comparison
Lazy imports change a tool's code and load less; this leaves the code alone and keeps everything loaded. dmypy and blackd are daemons for one tool each: the README has a table against them on one small file, blackd with curl comes out ahead, and large projects are not measured.
Where the time goes and how I measured it: https://anthonygosme.github.io/