Agent skill
review-mcode
Scan for hot loops over raw buffers that would benefit from MCode (native C) optimization
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/review-mcode
SKILL.md
Enter planning mode. Scan the codebase for MCode optimization opportunities. Use parallelism where possible.
MCode replaces AHK-interpreted tight loops with native C machine code embedded as base64. The project already has an MCode pipeline (tools/native_benchmark/native_src/) and a working example (src/gui/icon_alpha.ahk). Adding a new function to an existing MCode module is low cost — the infrastructure exists.
What Qualifies
All four must be true:
- Hot path — called frequently OR scales with data (per-window, per-pixel, per-byte). Use
query_function_visibility.ps1to check call frequency — a loop called 1x/session vs 100x/sec changes the MCode ROI. Usequery_callchain.ps1 <funcName> -Reverseto trace all invocation contexts. Usequery_timers.ps1to check if the candidate is inside a timer callback (hot path signal). - Pure buffer computation — operates on
Buffer/NumGet/NumPut, not AHK objects - Interpreter-bound — the bottleneck is AHK loop overhead, not an underlying Win32/native call
- Measurable — worst-case cost exceeds ~100μs (below that, DllCall overhead eats the savings)
What Does NOT Qualify
- AHK built-ins that already call native C —
StrPut,InStr,SubStr,Sort,RegExMatchetc. - Loops over AHK objects/Maps/Arrays — MCode can't read AHK objects without COM interop
- Functions where the expensive part is a DllCall — GDI+, Win32 API calls. The loop around them is not the bottleneck.
- Anything under ~100μs worst case — DllCall marshaling overhead cancels the gain
What to Look For
NumGet/NumPutinside loops (pixel processing, binary protocol parsing, buffer scanning)- Byte-by-byte or word-by-word buffer iteration
- Math-heavy loops with no AHK object interaction
- Any loop where removing the body makes it instant (= per-iteration AHK overhead dominates)
Reference
src/gui/icon_alpha.ahk— template for MCode embedding (base64 → CryptStringToBinary → VirtualProtect)tools/native_benchmark/native_src/icon_alpha.c— reference C source (no CRT, no imports, pure computation)tools/native_benchmark/— benchmark harness and native build pipeline
Explore Strategy
Focus on files with buffer/binary operations:
src/gui/gui_paint.ahk— rendering, pixel manipulationsrc/core/— icon extraction, process info, any binary data handlingsrc/shared/ipc_pipe.ahk— binary pipe protocol parsingsrc/pump/— icon resolution, bitmap processing- Any file with
NumGetorNumPutusage
Plan Format
For each candidate:
| File | Function | Loop Description | Est. Worst Case | Qualifies? | Why |
|---|---|---|---|---|---|
foo.ahk:42 |
ScanBuffer() |
NumGet loop over 256KB icon bitmap, ~65k iterations | ~65ms | Yes | Pure buffer, no AHK objects, scales with icon count |
bar.ahk:100 |
ParseWindows() |
Loop over window array calling WinGetTitle | ~2ms | No | Bottleneck is Win32 calls, not AHK loop |
For qualifying candidates, additionally note:
- Whether it fits into an existing MCode module (e.g.,
icon_alpha) or needs a new one - The C function signature it would need
- Any complication (pointer to AHK string, callback needed, etc.)
Ignore any existing plans — create a fresh one.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?