C-

C Performance

C performance optimization

Details

Language / Topic
cC
Category
Performance

Rules

balanced
- Profile before optimizing — use `perf`, `gprof`, or `callgrind` to identify actual bottlenecks instead of guessing.
- Use cache-friendly data layouts: prefer arrays of structs (AoS) or structs of arrays (SoA) based on access patterns — minimize cache misses.
- Minimize dynamic memory allocation in hot paths — use stack allocation, arena allocators, or pre-allocated pools for predictable performance.
- Profile with perf/gprof before optimizing.
- Use cache-friendly data structures (AoS vs SoA based on access patterns).
- Minimize malloc/free in hot paths — use arenas or pools.
- Enable compiler optimizations: `-O2` for production, `-O0 -g` for debugging.