# Cairo Optimization

> Improves Cairo performance after correctness is established, including hotspot profiling, arithmetic/loop optimization, and bounded-int hardening.

- Skill: `cartridge-gg/cairo-optimization` (Agent Skill, multi-file: 8 files)
- Install (CLI): `npx skillmds@latest add cartridge-gg/cairo-optimization`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cartridge-gg/cairo-optimization/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: Apache-2.0
- Author: cartridge-gg (https://skillmd.com/u/cartridge-gg)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/cartridge-gg/cairo-optimization

---


# Cairo Optimization

Apply only after tests pass and behavior is locked.

## When to Use

- Improving gas/resource usage in hot paths.
- Rewriting expensive loops/arithmetic patterns.
- Optimizing storage layout and integer choices.

## When NOT to Use

- Early feature prototyping without tests.
- Security review as a substitute for correctness proofs.

## Quick Start

1. Confirm baseline behavior with tests.
2. Profile target paths with `python3 scripts/profile.py profile`.
3. Apply one optimization class at a time.
4. Re-run tests and compare resource deltas.
5. Use anti-pattern/secure-pattern pairs to keep micro-optimizations explicit.
6. Encode stable optimization rules in `../evals/cases/contract_skill_benchmark.jsonl` to prevent regressions.
7. Run `cairo-auditor` on touched files to ensure no security regressions were introduced.

## Workflow

- Main optimization flow: [default workflow](workflows/default.md)

## References

- Detailed optimization rules: [legacy reference](references/legacy-full.md)
- Profiling workflow and troubleshooting: [profiling reference](references/profiling.md)
- Optimization anti-pattern pairs: [anti-pattern pairs](references/anti-pattern-pairs.md)
- Module index: [references index](references/README.md)

