Performance

Rendering Performance

When rendering a rinja template, you should prefer the methods

over .to_string() or format!(). While .to_string() and format!() give you the same result, they generally perform much worse than rinja's own methods, because fmt::Write uses dynamic methods calls instead of monomorphised code. On average, expect .to_string() to be 100% to 200% slower than .render().

Slow Debug Recompilations

If you experience slow compile times when iterating with lots of templates, you can compile Rinja's derive macros with a higher optimization level. This can speed up recompilation times dramatically.

Add the following to Cargo.toml or .cargo/config.toml:

#![allow(unused)]
fn main() {
[profile.dev.package.rinja_derive]
opt-level = 3
}

This may affect clean compile times in debug mode, but incremental compiles will be faster.