Optimizing Performance

Compilation Tips

Generally, you will want to compile with a release build, sometimes even for development:

cargo build --release

Enabling SIMD and using a nightly toolchain will allow you to take advantage of the simd feature.

You must first switch to a nightly Rust toolchain, then you can enable this like so in your Cargo.toml:

legato = { version = "0.1", default-features = false, features = ["simd"] }

Custom Nodes

The following tips generally can be of help:

  • Avoid allocation or system calls in any node definitions.
  • Avoid any locking primitives, prefer the rtrb crate for SPSC message passing.
  • If prediction is bad, branch at the entry of the function or consider branchless implementations
  • Consider polynomial approximations or LUT, if it meets your accuracy demands
  • Try to use nightly simd or auto-vectorization for math-heavy paths.