Skip to Content
Scalus Club is now open! Join us to get an early access to new features πŸŽ‰
DocumentationAdvanced OptimisationsAlgorithmic Optimisations

Algorithmic Optimisations

Before diving into compiler-level techniques, apply algorithmic optimizations. These give the biggest wins and are backend-agnostic. Scalus provides a library of Design Patterns for common cases:

  • Withdraw Zero β€” run heavy logic once via a stake validator instead of per-UTxO (O(N) instead of O(NΒ²))
  • UTxO Indexer β€” pass indexes in the redeemer for O(1) lookup instead of linear search
  • Transaction Level Minting β€” batch minting validation into a single check
  • Merkelized Validator β€” split large validators into smaller pieces, include only the branch you need

See the full OptimizedPaymentSplitterValidator example in scalus-examples/.../paymentsplitter/ for a real-world application of the withdraw-zero pattern.

What’s Next?

  • Design Patterns β€” full reference for every pattern listed above, with implementations and trade-offs.
  • Scala Metaprogramming β€” once the algorithm is right, eliminate per-call overhead with inline and compile-time evaluation.
  • Measuring Performance β€” quantify the impact of each pattern on real transaction fees.
Last updated on