Performance and cost optimization
Skill aneja5/forge-skills/skills/performance-and-cost-optimization
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.From its SKILL.md
npx -y skills add aneja5/forge-skills --skill performance-and-cost-optimizationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.2 KB, ~1.4k tokens by cl100k_base, as published. Nobody here has run it
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
observabilityfirst
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_tokensalways 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 —
EXPLAINplans 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.mdwritten - 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
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most caching build skills give in ~1.4k tokens
Counted across 103 of the 134 authors here whose files we hold, read 2026-09-06
- Prefer App Router and server componentsin 12 of 103, across 7 files
- Stay on a recent Next.js 16.x releasein 12 of 103, across 7 files
- Use the Bundle Analyzer to trim large dependenciesin 12 of 103, across 7 files
- Use Turbopack for day-to-day developmentin 11 of 103, across 6 files
- Fall back to webpack only for Turbopack bugs or webpack-only pluginsin 11 of 103, across 6 files
- Set a TTL on every cache entryin 10 of 103, across 9 files
- Check the official docs for your Next.js versionin 9 of 103, across 5 files
- Ensure the cache is not cleared unnecessarilyin 8 of 103, across 4 files
- Verify Turbopack is active when dev is slowin 8 of 103, across 4 files
- Run next dev for local developmentin 7 of 103, across 6 files
- Run next dev for local development with Turbopackin 6 of 103, across 2 files
- Append static extensions to dynamic URLs to trigger cachingin 6 of 103, across 3 files
Said here and by no other author read
- Write latency budgets per request type before optimizing
- Set cost budgets for every LLM call type
- Cap LLM input and output tokens
- Document model selection rationale per LLM call
- Use deterministic versioned cache keys
- Document TTLs and invalidation events per cache
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.