Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Performance And Cost Optimization

ASecurity

Use when setting latency budgets per request type, when tracking LLM cost per call type, when designing a caching strategy, when reviewing bundle size, when profiling a slow path, or when a service is approaching its latency or cost SLO.

3 stars
0 votes
0 copies
0 views
Added 5/28/2026
developmentrefactoringapidatabasefrontendbackendperformance

Works with

cliapi

Security Analysis

A100/100

Scanned 5/28/2026

$npx -y skills add aneja5/forge-skills --skill performance-and-cost-optimization --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Performance And Cost Optimization?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Performance And Cost Optimization
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aneja5-performance-and-cost-optimization/badge)](https://www.skillsdirectory.com/skills/aneja5-performance-and-cost-optimization)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: performance-and-cost-optimization
description: Use when setting latency budgets per request type, when tracking LLM cost per call type, when designing a caching strategy, when reviewing bundle size, when profiling a slow path, or when a service is approaching its latency or cost SLO.
---

# Performance and Cost Optimization

## Overview

Define what "fast enough" and "cheap enough" mean *before* optimizing anything. Output is `.forge/performance-budget.md` — latency budgets per request path, LLM cost budgets per call type, the caching strategy (key schema, TTLs, invalidation), frontend bundle budgets, and the profiling targets. Pairs with `observability` (the dashboards that measure compliance) and `scalability-analysis` (the growth projection that decides when to invest).

## When to Use

- A new service is being designed and there's no latency or cost target
- An LLM-heavy feature is shipping and per-call cost is unbounded
- The frontend bundle is growing organically and ship time is increasing
- A query or endpoint is approaching its SLO and the team is debating where to optimize
- Caching is being added ad-hoc with no key convention or invalidation story

## When NOT to Use

- A one-off script with no user-facing latency
- Pure refactoring or rename work with no perf surface
- "It feels slow" with no measurement — start with `observability` first

## Common Rationalizations

| Thought | Reality |
|---------|---------|
| "Premature optimization is evil" | Setting budgets isn't optimizing — it's defining done. You can't tell what's premature without a target. |
| "LLM costs are fine for now" | Unbounded token usage scales linearly with users. The first viral spike turns a $50/day bill into a $5000/day bill overnight. |
| "We'll cache later" | Cache invalidation designed after the fact creates stale-data bugs you find in production. Design the invalidation strategy with the cache. |
| "Bundle size doesn't matter, our users have fast internet" | You don't know that. Mobile carriers, hotel wifi, rural backhaul, parking-garage signal — all real. |
| "Profile when it's slow" | "Slow" is a feeling. Without a budget, you'll profile randomly or never. |
| "Auto-scaling fixes performance" | Auto-scaling fixes capacity, not per-request latency. A slow request stays slow under any cluster size. |

## Red Flags

- An endpoint in production with no latency SLO and no dashboard
- An LLM call with no `max_tokens`, no model selection rationale, and no cost tracking
- A cache layer with no documented TTL or invalidation event
- A frontend route loading >500KB of initial JS
- A backend hot path that has never been profiled
- A "background job" that takes >30s with no chunking or progress reporting
- Optimization work happening before measurement
- An LLM prompt that grows unbounded with conversation history

## Core Process

### Step 1: Define latency budgets per request type

In `.forge/performance-budget.md`:

| Path type | p95 budget | p99 budget | Source of truth |
|---|---|---|---|
| Interactive UI action (click → visible response) | 200ms | 500ms | Frontend RUM |
| Public API read | 500ms | 1s | Backend traces |
| Public API write | 800ms | 2s | Backend traces |
| Search / aggregation | 1s | 3s | Backend traces |
| Background job | 30s | 5min | Job runner |
| Email / webhook delivery | 5min | 30min | Queue worker |

Adjust per project, but write the numbers down. Every hot path gets a budget.

### Step 2: Set LLM cost budgets per call type

For every LLM call in the system, document:
- Model selection rationale (why Sonnet vs Haiku vs local)
- Input token cap (truncate or summarize context past N tokens)
- Output token cap (`max_tokens` always set)
- Cost target per call (e.g., "<$0.01 for the autocomplete call, <$0.05 for the summary call")
- Cost-per-user-per-day budget (the rate-limit threshold)
- Caching strategy if the same prompt recurs (prompt cache, response cache, or both)

Append to `.forge/performance-budget.md`.

### Step 3: Design caching strategy

For every cache layer:
- **Key schema** — explicit, deterministic, includes version (`v1:user:{id}:profile`)
- **TTL** — short for frequently-changing data (60s), long for slowly-changing (1h), forever for immutable (with versioned keys)
- **Invalidation events** — which mutations bust which cache keys, documented as a table
- **Negative caching** — cache "not found" for short TTL to absorb thundering-herd lookups
- **Stale-while-revalidate** for read-heavy paths where eventual consistency is acceptable
- **Failure mode** — what happens when the cache is down (fall through to source, or fail closed)

A cache without a documented invalidation event is a stale-data bug waiting to ship.

### Step 4: Set frontend bundle budgets

- Initial JS for any user-facing route: **<200KB gzip**.
- Initial CSS: <50KB.
- LCP-impacting resources (above-the-fold images): preloaded, properly sized.
- Code-split per route. Lazy-load heavy components (charts, editors, maps).
- Bundle analyzer in CI; budget breach blocks the build.

### Step 5: Identify profiling targets

For each service:
- Top 3 endpoints by traffic — profiled with production-shaped data
- Top 3 endpoints by latency — flame graphs captured, reviewed
- Top 3 database queries by cost — `EXPLAIN` plans attached to `.forge/database-design.md`
- Any code path inside a `setInterval`, `setTimeout`, or render loop

Profile *before* optimizing. Optimization without a baseline is decoration.

### Step 6: Define cost-tracking dashboards (cross-ref `observability`)

- Per-endpoint cost per request (compute + DB + cache + LLM + egress)
- Cost-per-active-user per day
- LLM spend per feature per day
- Top 10 most-expensive users per week (for usage-based pricing or abuse detection)

## Verification

- [ ] `.forge/performance-budget.md` written
- [ ] Every hot-path endpoint has a documented p95 and p99 latency budget
- [ ] Every LLM call type has model rationale, `max_tokens`, and cost target
- [ ] Every cache layer has documented key schema, TTL, and invalidation events
- [ ] Frontend bundle is <200KB initial JS per route (CI-enforced)
- [ ] Top traffic and top latency endpoints have been profiled with flame graphs
- [ ] Cost-per-user-per-day dashboard exists and has an alert threshold
- [ ] No LLM prompt grows unbounded with user input or conversation length

Attribution

aneja5aneja5
View sourceSee grades on GitHubMore from aneja5 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Clean Code

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

304955 votes

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

286712 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Writing Plans

Use when you have a spec or requirements for a multi-step task, before touching code

2927051 votes
View all in development →