RustAPI is built on the principle of Zero-Cost Abstractions. We do not compromise runtime performance for developer ergonomics; we strive to offer both.
Where possible, we use generics and impl Trait rather than Box<dyn Trait>. This allows the compiler to monomorphize code, inlining function calls and enabling optimizations that vtables prevent.
We are fully committed to the tokio ecosystem.
- IO-Bound: We use async IO for everything (database, cache, network).
- CPU-Bound: Heavy computation is offloaded to
spawn_blockingto avoid blocking the reactor.
We use Bytes and references where possible to avoid cloning Strings unnecessarily. The deserialization layer is tuned to borrow from the input buffer when feasible.
We don't guess; we measure.
- Micro-benchmarks: Use
criterionfor hot paths (serialization, routing). - Macro-benchmarks: Use
heyorwrkfor end-to-end HTTP throughput.
Important
A regression in a micro-benchmark is a blocking issue. We treat performance as a feature.
You might ask: "Does creating a struct for every action add overhead?" Answer: No. The compiler optimizes away the struct wrapper, leaving just the logic execution. It is zero-cost organization.