.claude/skills/sexp_bench/SKILL.md
# SEXP Benchmark Strategy ## Goal Measure and improve S-expression pipeline performance with a focus on: - Throughput per stage - Peak memory per stage - End-to-end behavior on realistic KiCad PCB inputs ## Pipeline Stages Benchmark these layers separately: - `tokenizer` - `ast` - `parser` (typed decode) - `encode` (typed encode to raw SEXP) - `pretty` (formatting) ## Dataset Dimensions Use a matrix over: - `depth`: shallow vs deep nesting - `size`: small, medium, large Recommended size buck
npx skillsauth add atopile/atopile .claude/skills/sexp_benchInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Measure and improve S-expression pipeline performance with a focus on:
Benchmark these layers separately:
tokenizerastparser (typed decode)encode (typed encode to raw SEXP)pretty (formatting)Use a matrix over:
depth: shallow vs deep nestingsize: small, medium, largeRecommended size buckets:
small: < 64 KiBmedium: 64 KiB .. < 1 MiBlarge: 1 MiB .. < 10 MiBFor each stage and sample:
mean_ms and percentile latency (median, p80)mem_before, mem_after, mem_deltastage_peak_increment (stage-local high watermark increase)cumulative_pipeline_peak and cumulative_peak_over_startKey interpretation:
mem_delta can still coexist with high stage_peak_increment.peak metrics are more informative than final deltas.Use this when validating real end-to-end impact (load -> dump -> reload) on a large board.
pyzig_sexp.so in each checkout you want to compare:source .venv/bin/activate
cd src/faebryk/core/zig
python -m ziglang build python-ext -Doptimize=ReleaseFast -Dpython-include=/usr/include/python3.14 -Dpython-lib=python3.14
git worktree add /tmp/atopile_pre_tokenizer_fix <baseline_commit>
Use Python with direct importlib loading of pyzig_sexp.so from each checkout. This avoids accidental rebuilds and keeps the comparison tied to the compiled artifact in that checkout.
from pathlib import Path
from time import perf_counter
import gc, importlib.util, sys
spec = importlib.util.spec_from_file_location(
"pyzig_sexp",
"src/faebryk/core/zig/zig-out/lib/pyzig_sexp.so",
)
mod = importlib.util.module_from_spec(spec)
sys.modules["pyzig_sexp"] = mod
spec.loader.exec_module(mod)
text = Path("panel.kicad_pcb").read_text(encoding="utf-8")
# warmup
obj = mod.pcb.loads(text)
out = mod.pcb.dumps(obj)
obj2 = mod.pcb.loads(out)
del obj, out, obj2
gc.collect()
runs = []
for _ in range(5):
gc.collect()
t0 = perf_counter()
obj = mod.pcb.loads(text)
t1 = perf_counter()
out = mod.pcb.dumps(obj)
t2 = perf_counter()
obj2 = mod.pcb.loads(out)
t3 = perf_counter()
runs.append((t1 - t0, t2 - t1, t3 - t2, t3 - t0))
del obj, out, obj2
print("AVG", " ".join(f"{sum(r[i] for r in runs)/len(runs):.3f}" for i in range(4)))
Report at minimum:
load_avg_sdump_avg_sreload_avg_stotal_roundtrip_avg_sPrioritize stage-local wins first, then validate global effects:
After each optimization pass:
Summarize gains in two views:
(depth, size) x stageAlways report:
development
How the Faebryk parameter solver works (Sets/Literals, Parameters, Expressions), the core invariants enforced during mutation, and practical workflows for debugging and extending the solver. Use when implementing or modifying constraint solving, parameter bounds, or debugging expression simplification.
development
How the Zig S-expression engine and typed KiCad models work, how they are exposed to Python (pyzig_sexp), and the invariants around parsing, formatting, and freeing. Use when working with KiCad file parsing, S-expression generation, or layout sync.
tools
How the Zig↔Python binding layer works (pyzig), including build-on-import, wrapper generation patterns, ownership rules, and where to add new exported APIs. Use when adding Zig-Python bindings, modifying native extensions, or debugging C-API interactions.
testing
Spec-driven planning for complex design tasks: when to plan, how to write specs as .ato files, and how to verify against requirements.