motoko-performance-optimizations
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
More from research-ag/motoko-skills
motoko-core-code-improvements
Optional, modular cleanups and style improvements to apply on new mo:core projects (or after mo:core migration). Covers import ordering, unused import cleanup, and single‑expression return removal, with detection checks and automation recipes.
33motoko-general-style-guidelines
Load when working with contents in *.mo files
32motoko-benchmarks-generation
How to write benchmarks in Motoko using bench‑helper. Covers project setup (mops.toml), bench file layout in bench/*.bench.mo, the Bench.Schema rows/cols model, and safe patterns for encode/decode, hashing, crypto, and allocation benches.
31motoko-dot-notation-migration
Use new dot-notation syntax in projects with mo:core dependency
31motoko-base-to-core-migration
Complete, AI-ready playbook to migrate Motoko projects from mo:base to mo:core — phases, renames, data structure changes, agent strategy, verification scripts, upgrade tests, and production rollout.
27motoko-compiler-warnings-fixes
Guidelines for fixing Motoko compiler warnings (moc). Use when asked to fix, suppress, or clean up Motoko compiler warnings from `dfx build --check`.
23