Operation Costs
| Operation | Relative Cost |
|---|---|
| Addition | 1x |
| Subtraction | 1x |
| Multiplication | 2-3x |
| Comparison | 5-10x |
| Min/Max | 5-10x |
| Select | 5-10x |
Key Strategies
1. Minimize Comparisons
Comparisons are expensive. Batch when possible:2. Use Smallest Types
3. Load Once, Use Multiple Times
4. Batch Arithmetic Before Comparisons
5. Use Built-in Min/Max
6. Store Results at End
Memory Optimization
Account Design
Heap Usage
Monitor heap usage for complex programs:Algorithm Optimization
Avoid Unnecessary Comparisons
Precompute When Possible
If values are known at instruction time, compute before encryption:Benchmarking
In tests, measure operation counts:Summary
- Minimize comparisons - they’re 5-10x more expensive
- Use smallest types - smaller ciphertexts, faster operations
- Load once - avoid redundant fetches
- Batch arithmetic - do all arithmetic before comparisons
- Store at end - minimize data store writes