In-process, or sidecar?
Chatboting’s chunker is now a 300-line Rust crate. The Python ingest worker on the same box must call it thousands of times a minute. Two ways to connect them.
The boundary is too small
The Python loop calls the Rust extension once per token, a million times per document. It is slower than before. Tap the flaw.
Tap the part that will not survive contact with reality — or press 1…4.
The boundary is too large
Six months in, the “chunker extension” has grown. Tap the box that should never have crossed into Rust.
Tap the part that will not survive contact with reality — or press 1…5.
“It’s just one unsafe block”
Your agent wants to skip a copy at the Python boundary. Judge the proposal.
I’ll pass the numpy buffer to Rust as a raw pointer and read it with an unsafe slice::from_raw_parts. Zero-copy, and it’s just one unsafe block, well commented.
WASM, or a sidecar?
VoiceKit’s voice-activity detector must run on the server and in a browser demo. Same 20 ms frame budget. Two designs.
Sizing a boundary
Order the steps for carving a Rust element out of a Python system, first to last. Then run a carve through them.
What survives this level
| unsafe — meaning, legitimacy, and its real cost | unsafe is a promise the compiler cannot check; its real cost is that a human must review it forever. |
| FFI: PyO3, WASM, CLI, sidecar — sizing the boundary | Give Rust a pure function with a flat data contract and cross the boundary as rarely as possible. |