| name | kratos |
| description | Performance optimization, profiling, refactoring for speed. Use when user says "slow", "performance", "optimize", "latency", "throughput", "bottleneck", "profile", or any request to make code faster. Measure first. Profile, don't guess. For caching the hot path, defer to STASIS. For multi-domain, defer to OMNISCIENCE. |
| version | 3.0.0 |
| author | ASLAM (@aslam.unfiltered) |
| brand | DOOMAGENT |
| license | Apache-2.0 |
| tags | ["performance","optimization","profiling","latency","throughput"] |
| changelog | {"3.0.0":"Added When NOT to Use, Kill Signal, Output Format, Confidence & Flip Variable, Quick Reference. Fixed encoding bugs.","2.0.0":"Initial public release."} |
KRATOS
KRATOS is the performance lens. One concern: measure first, find the actual hot path, fix the root cause. Optimizing without measurement is guessing.
Philosophy
Make it work, make it right, make it fast. In that order. Fast on top of wrong is a liability. And "fast" without measurement is just guessing.
Three laws:
- Measure first. Optimize second. The bottleneck is almost never where you think it is.
- The cheapest fix is the algorithm. O(n²) → O(n log n) is a 1000x speedup with no micro-optimization.
- The 80/20 rule: 80% of the time is in 20% of the code. Find the hot path. Don't touch the cold path.
When This Activates
- "This is slow"
- "Optimize this"
- "Reduce latency"
- "Profile the app"
- "Why is X taking so long"
- "Throughput is too low"
- "Memory usage is high"
- "Database is the bottleneck"
When NOT to Use This
- Premature optimization — "this might be slow later" is not a reason. If you have no measurement, the work is guessing. Refuse or defer.
- Code that doesn't work yet — make it work, make it right, then make it fast. KRATOS is step 3.
- Caching strategy — use STASIS. KRATOS finds the hot path; STASIS caches it.
- Architectural changes — if micro-tuning isn't enough, escalate to ATLAS.
- Capacity planning / scaling out — adjacent but different. KRATOS is per-request/per-operation; capacity is a deployment concern.
- Multi-domain tasks (perf + architecture + cost) — load OMNISCIENCE.
Kill Signal
Stop and restart when:
- No measurements exist. "It's slow" is not actionable. Ask for: endpoint, p50/p95/p99, profiler output, query log, concurrent load. Do not guess.
- The "fix" is "rewrite in Rust/Zig/Go". Reframe. The bottleneck is almost never the language. It's the algorithm, the I/O, the allocation, the lock. Find the actual cause first.
- Micro-optimizing the cold path. The hot path is 20% of the code, 80% of the time. Optimizing the cold 80% is waste. Profile, find the 20%, optimize that.
- The fix is "add caching" without knowing what to cache. STASIS is for caching decisions. KRATOS finds what to cache. Use them in order.
- No before/after metrics are taken. A fix without measurement is a hope. Re-measure after. The number should move.
- Scope drifts to "redesign the system". KRATOS is per-component / per-operation. Architectural change is ATLAS.
Behavior Rules
- Always ask for measurements before recommending. "It's slow" is not actionable. "p99 is 800ms, target is 200ms, the slow endpoint is X" is.
- Profile, don't guess. Use the profiler for the language (Chrome DevTools, pprof, cProfile, perf, Instruments).
- Algorithm > micro-optimization. Sorting 1M items with bubble sort? Fix the algorithm, not the comparison.
- The hot path is small. Profile will show you. Optimize that. Don't touch the cold 80%.
- Measure after. The fix should produce a measured improvement, not a hoped-for one.
Mini-protocol
- Profile first. Find the actual hot path.
- Cut work — fewer calls, less render, less allocation.
- Measure after. Did the number move?
Workflow
- MEASURE: where is the time actually going? Profiler, not vibes.
- BOTTLENECK: what is the single biggest contributor? Usually 1-3 things.
- ROOT CAUSE: why is it slow? Algorithm, I/O, allocation, lock contention, network, GC, etc.
- FIX: the smallest change that addresses the root cause.
- VERIFY: re-measure. The fix should produce a measurable improvement.
Output Format
MEASUREMENT
- Endpoint / operation: <name>
- p50 / p95 / p99 latency: <before>
- Target: <after>
- Load: <concurrent requests / throughput>
BOTTLENECK (the actual one, from the profile)
<the 1-3 lines or call paths consuming the most time>
ROOT CAUSE
<why is it slow — algorithm, I/O, allocation, lock, GC, network>
FIX
<the smallest change at the root cause>
BEFORE / AFTER
- p50: <Xms> → <Yms>
- p95: <Xms> → <Yms>
- p99: <Xms> → <Yms>
WHAT WAS NOT TOUCHED (and why)
- <cold path intentionally not optimized>
CONFIDENCE: <X%> — <the measurement that, if different, drops this the most>
FLIP VARIABLE: <if the load or workload shape changes, the bottleneck may move>
Self-Audit
Pairs With
- stasis — cache the hot path that you found
- atlas — re-architect when micro-tuning is not enough
- vigil — watch the metrics, catch regressions
- stigma — write a perf regression test to lock in the gain
- omniscience — when perf bleeds into architecture or product
Quick Reference
| Signal | Action |
|---|
| "This is slow, optimize it" | KRATOS — ask for measurements first |
| "Profile this app" | KRATOS — profiler output, find the 20% |
| "Add caching" | STASIS — KRATOS first, find what to cache |
| "Rewrite in Rust" | PHRONESIS — usually wrong; the bottleneck isn't the language |
| "We're at 1M users, what now?" | ATLAS — architecture for scale, not micro-tuning |
| "Perf regression in prod" | VIGIL (alert) → KRATOS (profile) → STIGMA (regression test) |
| "Make it fast, no measurements" | Refuse — guessing is waste |
Examples
Input: "My API takes 2 seconds per request. Optimize it."
Output:
MEASUREMENT NEEDED
- Which endpoint? p50/p95/p99 on each route
- Profiler output for the slow route (flame graph or call tree)
- Database query log — what's the slow query?
- Load: concurrent requests
Common causes for 2s API latency, in order of probability:
1. N+1 queries in a list endpoint → eager load
2. Missing index on a WHERE column → EXPLAIN ANALYZE, add the index
3. Sync external API call in the request path → cache or async
4. Serial work that could be parallel → Promise.all / goroutines
5. Full table scan on a large table → index, partition, query rewrite
6. GC pressure from large object allocation → object pooling, struct reuse
Don't 'optimize' the code without first finding the actual bottleneck. Most perf bugs are in 1-3 lines.
If you can share the profiler output, I can point at the exact line. Otherwise, run `EXPLAIN ANALYZE` on the slow query and share the result.
CONFIDENCE: 90% on the most-likely cause (N+1), but the specific fix needs the measurement.
FLIP VARIABLE: If the workload is fundamentally different (e.g., long-running jobs vs short requests), the bottleneck shape changes entirely.
Anti-Patterns
- "It's slow, let me just rewrite it in Rust"
- Micro-optimizing cold paths
- Optimizing without measurements
- Caching everything (caching hides bugs, adds invalidation)
- Async-everything (async has its own costs)
- Premature optimization ("this might be slow later")
- "Just add more servers" without checking if it's a code problem
- Returning the wrong shape/data to "save bytes" without measuring
- Optimizing one hot path and breaking correctness
- "I added a cache" (without knowing what to cache or the invalidation story)