Retext
For DevOps EngineersPerformance Optimization

DevOps Engineer Performance Optimization Prompts Templates

You learn where the time or memory actually goes, get a faster version that returns the same results, and know how to measure the gain. For devops engineers there's an extra layer: devOps engineers need help writing and reviewing infrastructure as code, CI/CD pipeline configs, shell scripts and monitoring rules, and with diagnosing failed deploys from logs. The prompt below adds your role context so the answer fits how you work.

Installs as a snippet — type ;perf to paste this prompt anywhere on your Mac.
Prompt Template
Help me make this code faster without changing its results.

## Code
Language and runtime: [e.g. Python 3.12]
[paste the slow code]

## How slow, and with what data
Current time or memory: [e.g. 40 seconds, 2 GB]
Input size: [e.g. two lists of 100,000 strings]
Target: [e.g. under 1 second]

## Constraints
- Results must stay identical, including order: [yes or no]
- Allowed to add dependencies: [yes or no]

## Instructions
- First explain where the cost comes from, with the complexity of the slow part.
- Suggest the change with the biggest gain first. Skip micro-optimizations unless I ask.
- Show how to measure before and after with a simple benchmark.
- Point out any tradeoff, like extra memory or less readable code.

## Output format
1. Bottleneck and why
2. Optimized code
3. Expected improvement in big-O terms
4. Benchmark snippet

About my work
- Platform and tools: [e.g. AWS, Terraform 1.8, GitHub Actions, Kubernetes 1.30]
- Environment this affects: [e.g. staging only, production with 3 regions]
- Constraints: [e.g. no downtime, must stay within the current IAM roles]

How to use this prompt

  1. 1

    Copy the prompt

    Use the copy button, or type its Retext trigger in any app to paste it.

  2. 2

    Open your AI assistant

    Start a new chat in ChatGPT, Claude, Gemini or whichever assistant you use, so earlier messages don't steer the answer.

  3. 3

    Fill in the brackets

    Replace every [bracketed] part with your real details. Specific inputs are what make the answer specific.

  4. 4

    Check and refine

    Read the result against the goal above, then reply with one change at a time.

Worked example

What you give it

Language: Python 3.12
Slow: about 40 seconds. Input: a and b are lists of about 100,000 strings each.
Results must keep the order of a: yes.

def find_common(a, b):
    result = []
    for x in a:
        if x in b and x not in result:
            result.append(x)
    return result

What a good answer looks like (shortened)

1. Bottleneck: "x in b" and "x not in result" scan whole lists, so each loop step is O(len(b)). Overall this is O(n x m), about 10 billion comparisons here.

2. Optimized code:
def find_common(a, b):
    b_set = set(b)
    seen = set()
    result = []
    for x in a:
        if x in b_set and x not in seen:
            seen.add(x)
            result.append(x)
    return result

3. Set lookups are O(1) on average, so this is O(n + m). Order of a is preserved.

4. Benchmark:
import timeit
print(timeit.timeit(lambda: find_common(a, b), number=1))

Tradeoff: two extra sets use memory roughly proportional to the inputs.

Tips for better results

  • •Always say which environment the change targets and ask for a plan or dry-run command before the apply step. It keeps a test idea from turning into a production change.
  • •Give real numbers in "How slow, and with what data." The right fix for 1,000 rows is often different from the right fix for 10 million.
  • •If you have profiler output, paste it into the Code section. It shows the AI where time really goes instead of where it seems to go.
  • •Avoid this: Asking for "faster code" without saying how slow it is or how big the input is, which leads to generic tips that may not matter.

Check before you use it: Check IAM permissions, open ports, secrets handling and destructive commands in any generated config or script before it touches a real environment.

Get the free prompt pack

Our best AI prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.

Variations

Memory instead of speed

Replace Target with: Peak memory under [e.g. 500 MB]. Focus on streaming and avoiding full copies.

Database bound

Add this section: ## Queries [paste the SQL and EXPLAIN output] and check for N+1 queries and missing indexes.

Frontend

Replace Code with the component and add: It re-renders [N] times on [action]. Find unnecessary renders and expensive work during render.

Save it as a Retext snippet

Retext is a free text expander for Mac. Save this prompt once, then type ;perf in any app (ChatGPT, Claude, your editor, a browser tab) and the full prompt is pasted in.

  1. Click Add to Retext. The prompt installs as a snippet with the trigger ;perf.
  2. Change the trigger in Retext if you prefer a different one.
  3. Type the trigger wherever you want the prompt, then fill in the brackets.

Frequently asked questions

Is it safe to use AI for Terraform or Kubernetes configs?

It is useful for drafts and reviews, but configs can contain subtle mistakes like overly broad permissions. Review every change with a plan or diff and test in a non-production environment first.

Should I profile before asking AI to optimize code?

Yes, if you can. A profile shows the real hot spot, and pasting it keeps the AI from optimizing a part of the code that barely matters.

Why did the optimized code give different results?

Common causes are switching to a set and losing order or duplicates, or changing float math. State in Constraints exactly what must stay identical.

How do I reuse this prompt without copying it every time?

Click Add to Retext to save it as a snippet. Then type ;perf in any Mac app, including your AI tool, and the full prompt is pasted in.

Related Templates

Get the free prompt pack

Our best AI prompts in one Markdown file, delivered by email. The templates here stay free either way — the pack just saves you the copying.