Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    Performance Optimization: Profile First, Then Fix

    1

    Profiles before touching code, fixes the real bottleneck, and proves the speedup with the same measurement.

    Free

    10 installsSecurity scanned
    Performance Optimization: Profile First, Then Fix

    Performance Optimization: Profile First, Then Fix

    Example session with this skill installed

    Use the performance-optimization skill on report.py. It takes about 8 seconds on 12,000 signups and the real nightly batch is 500,000. Make it fast enough for that.

    (report.py source: https://github.com/hemapriyan-rk/claude-rigor-skills/blob/main/examples/performance-optimization/report_before.py)

    • Read your context and instructions
    • Compiled the performance optimization

    Result

    Runtime: about 8 s → 0.15 s (~55×) on 12,000 signups, which includes interpreter startup. The 500,000-signup nightly size now takes 0.52 s for the report steps (unique_emails, count_by_country, to_csv), excluding the time to generate the fake input. The old code would have taken roughly 4 hours at that size, assuming the O(n²) scaling holds.

    Bottleneck

    cProfile on the 12k run showed 97% of the time (49.0 of 50.5 s, inflated by profiler overhead) in count_by_country. For every unique email it rescanned the whole signup list. unique_emails was another 1.2 s, because email not in seen searched a list. Both were O(n²) and CPU-bound.

    Change

    In report.py:

    • unique_emails: list(dict.fromkeys(...)). This is O(n) and keeps first-seen order.

    count_by_country: one pass builds a map of email to the country of its first signup, then each unique email is tallied from that map. This matches the old "first match wins" behavior. An email missing from signups is still skipped, as before.

    I did nothing to to_csv, which isn't on the hot path. A dict lookup was enough, so I didn't try anything more elaborate.

    Verified

    • I re-ran python report.py on the same 12,000 signups and compared it to baseline.txt. There are 0 differences.
    • The 500k timing is a single run. At that size, 489,616 of the emails are unique.
    • Only the 12k output was compared to the baseline. I didn't run the old code at 500k, so I haven't confirmed the two versions agree there.

    I also left an after.txt in the directory from the comparison. You can delete it.

    The changed functions in report.py, as written by the agent:

    def unique_emails(signups):
        return list(dict.fromkeys(s["email"] for s in signups))
    
    def count_by_country(signups, emails):
        first_country = {}
        for s in signups:
            first_country.setdefault(s["email"], s["country"])
        counts = {}
        for email in emails:
            country = first_country.get(email)
            if country is not None:
                counts[country] = counts.get(country, 0) + 1
        return counts
    

    Independently re-checked: 7.5 s → 0.2 s on the same 12,000 rows, byte-identical output.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    What it does

    Makes slow code or systems faster by measuring first. It profiles the real hot path, classifies the bottleneck (CPU, I/O, or memory), fixes the highest-leverage cause, and re-runs the same measurement to prove the speedup, with output checked to be unchanged.

    Why it exists

    "It's probably the loop" is a guess, and guesses cost a day when they're wrong. AI assistants tend to micro-optimize whatever looks inefficient. This skill makes measurement the first step and stops when the target is met.

    How it works

    1. Agrees on the target: which metric, on what input, and what number counts as done.
    2. Reproduces the slowness and profiles it, using a bundled table of profilers for Python, Node.js, Go, Java, Rust, C/C++, .NET, SQL, and browsers.
    3. Classifies the bottleneck before choosing a fix, so it doesn't speed up a loop when the time is spent waiting on I/O.
    4. Fixes in order of leverage: algorithm or query shape, then data structure, then I/O pattern, then micro-optimization.
    5. Re-runs the exact baseline and confirms the output is unchanged. A faster wrong answer is a regression.

    What you get

    Before/after numbers on the agreed metric, the profiler evidence for the bottleneck, the change with the reason it was picked, and how the result was verified.

    When not to use it

    Capacity planning for infrastructure you can't run, or tuning without any way to execute the code. Without shell access it gives you the exact profiling commands instead.

    Open source

    Part of claude-rigor-skills: 30 MIT-licensed skills that make AI show its work. The demo below, with its inputs, is in the examples folder.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    10 installs

    Downloaded by developers to date

    Free forever

    No account required to browse

    Trust & safety

    Security scanned

    Verified clean 5 days ago

    • Free to download with an account

    Listed5 days ago
    Updated3 days ago

    What's inside

    Frequently Asked Questions