cache-line-optimization

Align shared Rust data to 64-byte cache lines to reduce false sharing.

6|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/maschad/my-claude --skill cache-line-optimization
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cache-line-optimization
Source: https://github.com/maschad/my-claude/tree/main/skills/cache-line-optimization
Command: npx skills add https://github.com/maschad/my-claude --skill cache-line-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

False sharing occurs when multiple threads modify data that shares a cache line, causing cache invalidations and severe performance penalties. This skill teaches you how to align data structures to 64-byte cache lines in Rust to isolate hot fields and preserve throughput in multi-threaded code.

Core Features & Use Cases

  • Cache-line padded wrappers for hot shared fields using 64-byte alignment
  • Patterns for common data structures: producers/consumers ring buffers, per-bucket histograms, and atomic counters
  • Compile-time validation of alignment and practical benchmarking guidance to verify improvements
  • Practical guidance on when padding helps and how to measure its impact

Quick Start

Implement a 64-byte cache-line padded wrapper for a shared atomic field and benchmark the performance impact on your multi-threaded Rust code.

Frequently Asked Questions about cache-line-optimization

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

FAQPage Schema
What is false sharing and how does it affect concurrency in Rust?▼

False sharing in concurrent Rust programs occurs when multiple threads modify data sharing a cache line, triggering cache invalidations and severe performance penalties. Aligning shared data to 64-byte cache-line boundaries isolates hot fields and preserves throughput.

How do I align shared atomic counters to cache lines in Rust?▼

To align shared atomic counters in Rust, implement a 64-byte cache-line padded wrapper around the atomic field. This isolates the hot data to prevent false sharing and maintain multi-threaded throughput.

When do I need cache-line padding for multi-threaded Rust performance optimization?▼

You need cache-line padding for multi-threaded Rust performance optimization when multiple threads frequently modify shared data, such as in producer-consumer ring buffers, per-bucket histograms, or atomic counters, causing cache invalidations.

Does cache-line padding work for all data structures in concurrent Rust programs?▼

Cache-line padding applies to common concurrent Rust patterns like producer-consumer ring buffers, per-bucket histograms, and atomic counters across platforms with 64-byte cache lines. It requires implementing a padded wrapper and compile-time alignment checks.

How do I benchmark the performance impact of cache-line padding in Rust?▼

To benchmark the performance impact of cache-line padding in Rust, apply a 64-byte aligned padded wrapper to shared atomic fields and run practical benchmarks to validate throughput improvements in your multi-threaded code.