---
name: review-mcode-63b693a7ccbb
description: Scan for hot loops over raw buffers that would benefit from MCode (native C) optimization
user-invocable: true
disable-model-invocation: true
---
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:

1. **Hot path** — called frequently OR scales with data (per-window, per-pixel, per-byte). Use `query_function_visibility.ps1` to check call frequency — a loop called 1x/session vs 100x/sec changes the MCode ROI. Use `query_callchain.ps1 <funcName> -Reverse` to trace all invocation contexts. Use `query_timers.ps1` to check if the candidate is inside a timer callback (hot path signal).
2. **Pure buffer computation** — operates on `Buffer` / `NumGet` / `NumPut`, not AHK objects
3. **Interpreter-bound** — the bottleneck is AHK loop overhead, not an underlying Win32/native call
4. **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`, `RegExMatch` etc.
- **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` / `NumPut` inside 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 manipulation
- `src/core/` — icon extraction, process info, any binary data handling
- `src/shared/ipc_pipe.ahk` — binary pipe protocol parsing
- `src/pump/` — icon resolution, bitmap processing
- Any file with `NumGet` or `NumPut` usage

## 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.


---
Source attribution: cwilliams5
Original project: https://github.com/cwilliams5/Alt-Tabby/blob/6e941fe6d8344facc4f24c373f41999ff6da4c04/.claude/skills/review-mcode/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2025 Cody Williams

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: cwilliams5
Original project: https://github.com/cwilliams5/Alt-Tabby/blob/6e941fe6d8344facc4f24c373f41999ff6da4c04/.claude/skills/review-mcode/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering
Roles: Backend Developer, Data Engineer, DevOps / SRE
Specialties: Backend
Tools: Ahk
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 65554938eb76195c7f551249a2c2b3f5f9bc1c92d4b35c0bf74e97df5423594f
