motoko-performance-optimizations
Installation
SKILL.md
Motoko Performance Optimizations
What This Is
An extensible guide for speeding up Motoko code safely and predictably. It focuses on mechanical, behavior-preserving improvements: allocation reduction, fixed-width arithmetic, block processing, efficient Text building, and clear loop shapes. Use this skill when you want to improve throughput/latency without changing semantics.
- Benchmarking details and harnesses live in: skills/benchmarks-generation/SKILL.md
- Style and safe refactors that often precede perf work: skills/code-improvements/SKILL.md
- Dot-notation improvements that reduce verbosity/overhead: skills/dot-notation-migration/SKILL.md
Quick Wins (General)
-
Minimize allocations in hot paths
- Avoid materializing entire buffers just to iterate (e.g., prefer indexing
Blobdirectly). - Reuse lengths and capacities; cache
size()calls to a local variable.
- Avoid materializing entire buffers just to iterate (e.g., prefer indexing
-
Prefer fixed-width arithmetic in tight loops
- Keep shifts/masks on
Nat32/Nat64intermediates; avoid widening toNatmid-loop.
- Keep shifts/masks on