Audit AI Code Diffs for Performance Regressions

This prompt scans code changes for silent performance killers like N+1 queries, unindexed filters, and memory leaks before you merge them.

Agent prompt for Claude Code and Cursor

Prompt

Prompt
Act as a Senior Backend Staff Engineer. Your job is to audit a code diff for performance regressions that standard unit tests miss. Before starting, ask me these 3 questions: 1. What framework or language is this project using? 2. What is the primary data storage system or database? 3. Is the code intended for high-concurrency or batch processing? After I answer, I will paste the code diff. You must analyze the diff strictly for: 1. N+1 query patterns in loops. 2. Database operations on unindexed columns. 3. Potential unbounded memory usage in data collection. 4. Improper connection pool handling or open file descriptors. Output format: # Performance Audit Report ## High-Risk Findings (Table with columns: Issue, Location, Impact, Remediation) ## Optimization Suggestions (Numbered list of specific code changes) ## Confidence Score (A percentage based on available context) This is not professional software architecture advice; consult a senior systems architect for mission-critical deployments.

Example output

Performance audit findings and fixesTwo high-risk issues found, confidence 92%
  1. N+1 QueryuserService.js:42One query per user in loop; use a single WHERE IN query
  2. Unindexed Filterdb.js:115Full table scan on status; add index to users.status
  3. Limit bulk updatesCap at 50 records to prevent heap memory exhaustion
  4. Close transaction in catchPrevents connection pool starvation

Example for: an Express.js API handling user profile updates. # Performance Audit Report ## High-Risk Findings | Issue | Location | Impact | Remediation |
| :--- | :--- | :--- | :--- |
| N+1 Query | userService.js:42 | Executes 1 query per user in loop | Use Promise.all with a single 'WHERE IN' query |
| Unindexed Filter | db.js:115 | Full table scan on 'status' field | Add index to 'users.status' column | ## Optimization Suggestions 1. Refactor the getUserProfiles loop to fetch all IDs first, then execute one query to retrieve the dataset. 2. Apply a limit of 50 records to the bulk update function to prevent heap memory exhaustion during large batch processing. 3. Close the database transaction block explicitly in the catch clause to prevent connection pool starvation. ## Confidence Score 92%

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces the model to establish technical context before evaluating the code.
  • Targets specific anti-patterns like N+1 queries and memory leaks.
  • Requires a structured table output for clear, actionable remediation steps.

Use this when reviewing PRs or AI-generated code blocks in Claude Code, Cursor, or GitHub Copilot. Paste your diff after answering the three setup questions to identify silent bottlenecks.

Common edits

  • Adjust the list of performance checks if your stack uses NoSQL or specific caching layers like Redis.
  • Ask the model to provide the exact refactored code block instead of just suggestions.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

AI Coding AgentsClaude Code

Audit PR Git Diffs for Scope Creep and Churn

Reviews git diff statistics and patch files to immediately flag out-of-scope edits, accidental whitespace formatting churn, and unrequested dependency updates.

AI Coding AgentsClaude Code

Review AI Pull Requests for Phantom Imports and Bloat

Audits pull request diffs generated by coding agents to flag fake dependencies, single-call wrappers, and premature abstractions.

AI Coding AgentsClaude Code

Verify the Coding Agent's 'Done' Claim Against the Diff and Test Output

Checks each claim in a coding agent's final summary against the actual diff and test runs, marks it verified, unverified or contradicted with evidence, and lists unmentioned changes, skipped tests and stubs.

AI Coding AgentsClaude Code

Pre-Merge Self-Review of a Git Diff: Correctness, Security, and Test Gaps

Has Claude Code review a branch diff like a skeptical maintainer, producing severity-ranked findings with evidence and a clear merge, fix, or block recommendation. Use it before opening or approving a pull request.

AI Coding AgentsClaude Code

Evaluate Coding Agent Test Suites for False Positive Traps

Audits agent-generated unit tests to catch tautological assertions, over-mocking, and tests that still pass when core business logic is disabled.

AI Coding AgentsClaude Code

Create Automated Verification Loops for Long-Running Coding Agents

Generate a deterministic shell pipeline that combines linting, isolated unit testing, and diff-budget monitoring to validate AI agent code changes.