r/learnrust • • 1d ago

The Pi agent in Rust: 10 faster startup, 7 less memory!

I've been learning about the Pi agent and decided to rewrite it in Rust. Now that I've finished a lot of the work, I'd like to show how much faster Rust (rpi) is than TypeScript (Pi). Here are the results:

Metric rpi (Rust) Pi (TypeScript) Difference
--version 17.5 ms 169.5 ms 9.7× faster
Cold start 17.7 ms 189.5 ms 10.7× faster
RSS when ready 12.0 MiB 91.5 MiB 7.6× smaller
Install size 21.8 MiB ~385 MiB ~18× smaller

Rust is really cool!

2 Upvotes

9 comments sorted by

3

u/koopa1338 1d ago

Performance and memory usage were the main reason to drop pi. The important part of pi is that it can extend itself, which is fairly trivial when using a language like typescript. How do you plan to solve that feature in your rust port?

0

u/bigfish-rpi 1d ago

Rust doesn't have eval, so I went with a plugin ABI. Several extensions have been released.

1

u/koopa1338 20h ago

Mind sharing the repository and how to build plugins?

1

u/thicket 1d ago

Nice speed and memory numbers. Were there any improvements or compromises you had to make in doing the rewrite? For example, a plugin architecture seems like a significant improvement over eval-ing some untrusted code. 

2

u/bigfish-rpi 17h ago

Thanks! Big improvement: typed, versioned native cdylibs instead of eval-ing TS at startup. No Jiti tax.

repo : https://github.com/bigfish1913/pi-rust

1

u/Bright-Historian-216 1d ago

what's Pi agent? i've googled it and it shows me an AI harness. would you really care about run time and storage size if that were the case?

1

u/bigfish-rpi 17h ago

Yeah, Pi is a harness — that's exactly why it matters to me. There's a real issue where extension loading pushed startup to ~21s because Jiti blocks the main thread. Also, if you want to run your agent on Termux or a phone, a low resource footprint is necessary. rpi keeps the same harness model and plugin ABI. That's my whole point.