Advanced Smart Contract Optimisations
Optimize your Cardano validators to reduce script size and execution costs. This section covers advanced techniques to make your smart contracts more efficient on-chain.
Why Optimize?
On Cardano, validators consume blockchain resources:
- Memory usage - Affects transaction fees
- CPU execution steps - Limited per transaction
- Script size - Larger scripts cost more to deploy and execute
Optimization reduces these costs, making your DApp more economical for users.
Optimization Techniques
- Macros - Inline constants and conditional code generation at compile-time
- Direct Script Context Access - Efficiently extract specific fields without full deserialization
- Scalus Intermediate Representation (SIR) - Understand and optimize the compilation pipeline
- UPLC Optimizations - Apply low-level optimizations to reduce execution costs
When to Optimize
- After functionality is correct - Get it working first, then optimize
- When hitting limits - Transaction size or execution budget constraints
- For production deployment - Reduce user costs and improve UX
- Iteratively - Profile, optimize, measure, repeat
Last updated on