cpp-performance

Detect and fix C++ performance smells in hot loops, containers, allocations, and synchronization.

6|2|Updated May 6, 2026
One-click install
npx skills add https://github.com/sek788432/Stock-Back-Test-System --skill cpp-performance-sek788432
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cpp-performance
Source: https://github.com/sek788432/Stock-Back-Test-System/tree/main/.agents/skills/cpp-performance
Command: npx skills add https://github.com/sek788432/Stock-Back-Test-System --skill cpp-performance-sek788432

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? C++ code in trading engines, indicators, and replay pipelines often ships with hidden performance problems—O(n^2) loops, unnecessary copies, wrong containers, and virtual calls in hot paths—that only surface as slow backtests or regressed benchmarks. This Skill gives reviewers and authors a concrete checklist to find and fix those smells with measurement, not guesswork. ## Core Features & Use Cases - Smell detection checklists: Tables of concrete anti-patterns for containers, copies/allocations, virtual calls, algorithms, I/O, strings, synchronization, and memory layout, each paired with a specific fix. - Measure-first workflow: Enforces a measure → fix → re-measure discipline, with profiling guidance (perf, Instruments, WPA/VTune) and rules for documenting reproducible before/after benchmarks. - Repository-specific guardrails: Ties optimization work to the project's hot paths (engine bar loop, indicator update(), replay, data prefetch) and forbids unmeasured optimizations, premature SIMD, and unjustified caches. - Use Case: While reviewing a pull request that adds a std::map lookup inside the engine's per-bar loop, use this Skill to flag the container choice, suggest a measured alternative, and require benchmark evidence before merge. ## Quick Start Ask the AI to review a C++ file or diff for performance problems in hot paths using the cpp-performance checklist.

Frequently Asked Questions about cpp-performance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find performance problems in C++ hot loops?▼

Profile first with perf record -g on Linux, Instruments on macOS, or WPA/VTune on Windows to locate the real bottleneck. Then scan the identified hot code against checklists for containers, allocations, virtual calls, and synchronization smells.

When should I use std::unordered_map instead of std::map?▼

Use std::unordered_map for measured hot lookups that do not need ordering, since std::map pays tree traversal and poor cache locality costs. Measure first and review determinism requirements before switching.

Should I avoid all unnecessary copies in C++ code?▼

No. Outside measured hot paths, redundant copies of small trivial types are permitted when they simplify APIs or control flow. Reserve strict copy avoidance for documented hot paths or large payloads.

Can I add a cache to speed up repeated computations?▼

Only when the computation measurably dominates runtime, the hit rate is provably above 50 percent on real workloads, and invalidation has a defined trigger. Document keys, eviction policy, max size, and expected hit rate.

Why is std::function a problem inside tight loops?▼

std::function adds indirection and potential allocation per call in hot paths. Replace it with a templated callable, concrete type, or a cheap function reference view when the callable is created or invoked per bar or per tick.