xiaohongshu
xiaohongshu
cc-performance-tuning
Enforce measure-first discipline for code optimization using a 7-step gated decision tree and 40-item checklist. Use when code is too slow, has performance issues, timeouts, OOM errors, high CPU/memory, or doesn't scale. Triggers on: profiler hot spots, latency complaints, unresponsive UI, memory...
Full skill instructions
Production down? Losing money? User panicking? Especially then:
Minimum crisis protocol (non-negotiable):
This skill covers: Single-threaded, single-process code tuning for general-purpose computing.
NOT covered (need specialized guidance):
| Threshold/Rule | Value | Source |
|---|---|---|
| Hot spot concentration | <4% causes >50% runtime | Knuth 1971 |
| Failed optimization rate | >50% produce negligible or negative results | p.607 |
| Compiler optimization gains | 40-59% improvement possible | p.596 |
| Interpreted vs compiled | PHP/Python >100x slower than C++ | Table 25-1 |
| I/O vs memory | ~1000x difference | p.591 |
Key Principles:
PREREQUISITE: Only apply these patterns AFTER profiling confirms the specific code is in the <4% hot path. Applying without measurement is a skill violation.
// BEFORE: Causes page fault on every access [ANTI-PATTERN]
for (column = 0; column < MAX_COLUMNS; column++) {
for (row = 0; row < MAX_ROWS; row++) {
table[row][column] = BlankTableElement();
}
}
// AFTER: Page fault only when switching rows (up to 1000x faster)
for (row = 0; row < MAX_ROWS; row++) {
for (column = 0; column < MAX_COLUMNS; column++) {
table[row][column] = BlankTableElement();
}
}
// BEFORE: Compound test every iteration [ANTI-PATTERN]
found = false;
i = 0;
while (!found && i < count) {
if (item[i] == target) found = true;
i++;
}
// AFTER: Single test per iteration (23-65% faster)
// Place sentinel past end of search range
item[count] = target; // sentinel
i = 0;
while (item[i] != target) {
i++;
}
if (i < count) {
// found at position i
}
// BEFORE: Testing invariant condition every iteration [ANTI-PATTERN]
for (i = 0; i < count; i++) {
if (type == TYPE_A) {
processTypeA(item[i]);
} else {
processTypeB(item[i]);
}
}
// AFTER: Test once outside loop (19-28% faster)
if (type == TYPE_A) {
for (i = 0; i < count; i++) {
processTypeA(item[i]);
}
} else {
for (i = 0; i < count; i++) {
processTypeB(item[i]);
}
}
// BEFORE: Expensive operation [ANTI-PATTERN]
if (Math.sqrt(x) < Math.sqrt(y)) {
// ...
}
// AFTER: Algebraically equivalent, 90-99.9% faster
if (x < y) { // when x,y >= 0
// ...
}
Decision Tree (STRICT ORDER - Do NOT skip steps):
Each step is a gate. Skipping steps = wasted effort or masked problems.
1. Is the program correct and complete?
NO -> Make it correct first. STOP optimization.
YES -> Continue
2. Have you measured to find the actual bottleneck?
NO -> Profile/measure first. Do NOT guess.
YES -> Continue
3. Can requirements be relaxed?
YES -> Relax requirements. Done.
NO -> Continue
4. Can design/architecture solve it?
YES -> Fix design. Done.
NO -> Continue
5. Can algorithm/data structure solve it?
YES -> Change algorithm. Done.
NO -> Continue
6. Can compiler flags help?
YES -> Enable optimizations. Measure.
NO -> Continue
7. Is it in the <4% that causes >50% of runtime?
NO -> Do NOT optimize this code. Find actual hot spot.
YES -> PROCEED with code tuning
1. Save working version (cannot revert without backup)
2. Make ONE change (multiple changes = unmeasurable)
3. Measure improvement (same workload, before/after)
4. Keep if faster, revert if not (no "close enough")
5. Repeat
Logic:
Loops:
Data:
Expressions:
Checklist: checklists.md Output Format:
| Item | Status | Evidence | Location |
|---|---|---|---|
| Measured before tuning? | VIOLATION | No profiler/measurement found | N/A |
| Loop unswitching opportunity | WARNING | Invariant if (debug) inside loop | app.py:142 |
| Severity: |
| Excuse | Reality |
|---|---|
| "Fewer lines of code is faster" | No predictable relationship; unrolled loops often 60-74% faster [p.603] |
| "I know this operation is slow" | You must measure; rules change with every environment change |
| "I'll optimize as I go" | You'll spend 96% of time on code that doesn't matter [Pareto] |
| "Experience tells me where bottlenecks are" | No programmer has ever predicted bottlenecks without data [Newcomer] |
| "This clever trick will be faster" | Compilers optimize straightforward code better than tricky code [p.596] |
| "We need to rewrite in assembler now" | Usually <4% of code causes >50% of runtime; find it first [Knuth 1971] |
| "Fast code is as important as correct code" | Correct first, fast second. Always. |
| "I already optimized this; it will stay optimized" | Re-profile after any compiler/library/environment change |
| "This optimization always works" | Results vary wildly by language; Python -27% for loop unrolling [p.623] |
| "The theory says this should be faster" | Theory doesn't always hold; Visual Basic -94% on polynomial strength reduction [p.636] |
| "I don't need to profile small changes" | If not worth profiling, not worth degrading readability for [p.609] |
| Crisis: "We're losing $X/minute!" | Guessing wrong = paying that $X until you find real cause. 60-sec profile saves hours. |
| Crisis: "No time to profile!" | Wrong guess costs more time than profiling. Panic causes cascading errors. |
| Sunk cost: "I already spent 4 hours optimizing" | Time invested doesn't validate method. Revert all, apply with measurement. |
| Sunk cost: "It seems faster now" | "Seems faster" is not data. You may have made some faster, others slower. |
| Success streak: "I've been right 5 times" | Past success doesn't change physics. Calibration illusion: 5 wins don't predict win 6. |
| After | Next |
|---|---|
| Optimization complete | Verify design not degraded |
| Structure degraded | cc-refactoring-guidance |
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience