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 Blob directly).
    • Reuse lengths and capacities; cache size() calls to a local variable.
  • Prefer fixed-width arithmetic in tight loops

    • Keep shifts/masks on Nat32/Nat64 intermediates; avoid widening to Nat mid-loop.
Related skills
Installs
31
First Seen
Mar 27, 2026