optimize-benchmarks

Runs iterative Rust benchmark cycles to optimize syncpack-specifier parsing performance.

2.1k|73|Updated Aug 17, 2017
One-click install
npx skills add https://github.com/JamieMason/syncpack --skill optimize-benchmarks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimize-benchmarks
Source: https://github.com/JamieMason/syncpack/tree/main/.claude/skills/optimize-benchmarks
Command: npx skills add https://github.com/JamieMason/syncpack --skill optimize-benchmarks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Optimizing Rust code without a disciplined process leads to unmeasurable changes, regressions, and wasted effort. This Skill provides a structured, repeatable loop for improving the performance of the syncpack-specifier crate: benchmark, identify bottlenecks, apply one change, verify tests, measure against baseline, and repeat.

Core Features & Use Cases

  • Baseline Benchmarking: Saves criterion baselines with cargo bench -p syncpack-specifier -- --save-baseline before so every change is measured against a known reference.
  • Guided Bottleneck Analysis: Prioritizes the hot path (Specifier::create, parser::is_range, parser::is_exact, regexes) and catalogs known optimization opportunities ranked by impact, such as replacing regexes with char-based parsing.
  • Safe Iteration Discipline: Enforces one optimization per cycle, requires tests to pass before benchmarking, and mandates reverting regressions immediately.
  • Use Case: A maintainer notices semver specifier parsing is slow in a large monorepo. The Skill runs the benchmark suite, finds that is_range tries 12 regexes sequentially, replaces them with first-byte dispatch, verifies tests pass, and confirms a measurable percentage improvement against the baseline.

Quick Start

Run the optimize-benchmarks loop on the syncpack-specifier crate and report the before and after benchmark percentages for each accepted change.

Frequently Asked Questions about optimize-benchmarks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I benchmark a Rust crate with cargo bench?

Run cargo bench with a saved baseline using cargo bench -p syncpack-specifier -- --save-baseline before, then compare later runs with --baseline before. Criterion reports percentage changes so improvements and regressions are visible per benchmark.

How to replace regex with faster parsing in Rust?

Replace simple regexes like exact semver patterns with byte or char iteration over the string, which avoids regex engine setup and capture allocation. For sequential regex checks, dispatch on the first character so only relevant validators run.

Should I use lazy_static or OnceLock for regex compilation?

std::sync::OnceLock is preferred over lazy_static since Rust 1.80 because it removes an indirection layer and is zero-cost after initialization. However, if regexes are replaced with char-based parsing, neither is needed.

What should I do when a benchmark shows a regression?

Revert the change immediately and try a different approach. Each optimization must be a single isolated change so regressions are attributable, and tests must pass before any benchmark comparison is trusted.

When should I stop the performance optimization loop?

Stop when the user requests it, when no bottlenecks remain in the benchmark output, or when gains fall below one percent across all benchmarks. Do not optimize code paths that never appear in benchmark results.