cpu-cache-opt

cpu-cache-opt is a skill for Claude Code, Codex from mohitmishra786/low-level-dev-skills. It costs 94 tokens per session (1,894 once invoked), scanned A, original, MIT.

A guide to improving how C, C++, and Rust programs use the CPU cache, the small fast memory near the processor. It covers cache misses, data layout, false sharing between threads, prefetching, and measurement with perf.

In plain words
What is it for?
Use it to measure cache behavior, investigate false sharing, choose between array-of-structures and structure-of-arrays layouts, add prefetching, and redesign cache-heavy code.
Why use it?
It helps explain why code can be slow even when its algorithm looks efficient. It shows how memory layout and multiple threads can cause the processor to wait for data.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

not rated 310repo +7 14d ago A scan Socket: passSnyk: passSkillSpector: pass 94 tokens original MIT

Good fit Use it to measure cache behavior, investigate false sharing, choose between array-of-structures and structure-of-arrays layouts, add prefetching, and redesign cache-heavy code.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add mohitmishra786/low-level-dev-skills --skill cpu-cache-opt
Clone the repo
git clone --depth 1 https://github.com/mohitmishra786/low-level-dev-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cpu-cache-opt

README.md
[![agentmods](https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt/github.svg)](https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt)
Your own site
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cpu-cache-opt

Your own site · 80×15
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/cpu-cache-opt.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 94 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,894 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • Socket pass 15 Sept 2026
  • Snyk pass 15 Sept 2026
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00094 $0.01894
Opus 5.5 $0.00038 $0.00758
Sonnet 5.5 $0.00019 $0.00379
Haiku 4.5 $0.00009 $0.00189

Measured 3mo ago against content hash 9f4b4c6784f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cpu-cache-opt scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/low-level-programming/cpu-cache-opt/SKILL.md · 222 lines

How it starts

The opening of the file, as written. The whole thing — 222 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CPU Cache Optimization

Purpose

Guide agents through cache-aware programming: diagnosing cache misses with perf, data layout transformations (AoS→SoA), false sharing detection and fixes, prefetching, and cache-friendly algorithm design.

Triggers

  • "My program has high cache miss rates — how do I fix it?"
  • "What is false sharing and how do I detect it?"
  • "Should I use AoS or SoA data layout?"
  • "How do I measure cache performance with perf?"
  • "How do I use __builtin_prefetch?"
  • "My multithreaded program is slower than single-threaded due to cache"

Workflow

1. Measure cache performance

# Basic cache counters
perf stat -e cache-references,cache-misses,cycles,instructions ./prog

# L1/L2/L3 miss breakdown
perf stat -e \
    L1-dcache-load-misses,\
    L1-dcache-loads,\
    L2-dcache-load-misses,\
    LLC-load-misses,\
    LLC-loads \
    ./prog

# Cache miss rate = L1-dcache-load-misses / L1-dcache-loads
# > 5% is concerning; > 20% is severe

# False sharing detection
perf stat -e \
    machine_clears.memory_ordering,\
    mem_load_l3_hit_retired.xsnp_hitm \
    ./prog

2. Cache line basics

  • Cache line size: 64 bytes on x86-64, ARM (most platforms)
  • L1 cache: 32–64 KB, ~4 cycles latency
  • L2 cache: 256 KB–1 MB, ~12 cycles latency
  • L3 cache: 6–64 MB, ~40 cycles latency
  • Main memory: ~200–300 cycles latency
// Check cache line size
long cache_line = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);

// Align data to cache line
struct alignas(64) HotData {
    int counter;
    // ... 60 bytes of data that fit in one line
};

// C
typedef struct {
    int x;
} __attribute__((aligned(64))) AlignedData;

3. AoS vs SoA data layout

// AoS (Array of Structures) — default layout
struct Particle {
    float x, y, z;     // position (12 bytes)
    float vx, vy, vz;  // velocity (12 bytes)
    float mass;         // (4 bytes)
    int   flags;        // (4 bytes)
};
Particle particles[N];  // Bad for loops that only need position

// Problem: accessing particles[i].x loads x,y,z,vx,vy,vz,mass,flags
// But we only need x,y,z → 75% of loaded data is wasted

// SoA (Structure of Arrays) — cache-friendly for SIMD + sequential access
struct ParticlesSoA {
    float *x, *y, *z;
    float *vx, *vy, *vz;
    float *mass;
    int   *flags;
};

// Accessing x[i] for i=0..N loads 16 consecutive x values → 0% waste
// Also auto-vectorizes better

Read the full file on GitHub · 222 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 222 lines · 94 tokens per session scan A 9f4b4c6784f5

Subscribe to this mod's changes

cpu-cache-opt is a skill published in the GitHub repository mohitmishra786/low-level-dev-skills (310 stars, last pushed 14d ago), licensed MIT. It adds 94 tokens to every session and 1,894 once invoked, about $0.0004 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

cpu-cache-opt compared with skills from other repositories

cpu-cache-opt next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
cpu-cache-optmohitmishra786/low-level-dev-skillsSkill31014d agoMITA94Claude Code, Codex
header-only-c-cpp-ingestionalivirgo/Major-AI-SkillsSkill6todayMITA25Claude Code
zoom-meeting-sdk-unrealanthropics/knowledge-work-pluginsSkill38ktodayApache-2.0A41Claude Code
cudnn-installNVIDIA/skillsSkill4.3ktodayApache-2.0A49Claude Code, Codex
ccclNVIDIA/skillsSkill4.3ktodayApache-2.0A206Claude Code, Codex
doca-argpNVIDIA/skillsSkill4.3ktodayApache-2.0A277Claude Code
address-sanitizerRedHatProductSecurity/prodsec-skillsSkill2084d agoApache-2.0A35Claude Code