[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81849":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":16,"stars30d":17,"stars90d":13,"forks30d":13,"starsTrendScore":18,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":34,"readmeContent":35,"aiSummary":36,"trendingCount":13,"starSnapshotCount":13,"syncStatus":18,"lastSyncTime":37,"discoverSource":38},81849,"snarf","cong-or\u002Fsnarf","cong-or"," Cache-line false sharing linter for Rust structs","",null,"Rust",32,0,25,1,4,7,2,42.7,"MIT License",false,"main",[24,25,26,27,28,29,30,31,32,33],"cache-line","ci","concurrency","false-sharing","linter","mesi","no-std","performance","rust","static-analysis","2026-06-13 04:01:31","# snarf\r\n\r\nCache-line false sharing linter for Rust structs.\r\n\r\n![snarf demo](assets\u002Fdemo.gif)\r\n\r\n---\r\n\r\nFinds Rust structs where atomic or contended fields share a cache line with other fields. This is potential false sharing, not proven — snarf detects the layout but not runtime behavior, so you decide which fields are actually contended.\r\n\r\n[The Slowdown That Doesn't Show Up in Profiles](https:\u002F\u002Fcong-or.xyz\u002Ffalse-sharing-cache-lines.html) — why this matters.\r\n\r\n---\r\n\r\n### Install and run\r\n\r\n```\r\ncargo install cargo-snarf\r\ncargo snarf\r\n```\r\n\r\nNo output means no issues found. If snarf finds contended fields sharing a cache line, it prints a layout diagram and exits non-zero. In a workspace it discovers all crates automatically.\r\n\r\nsnarf requires nightly Rust to get exact type sizes via `cargo +nightly build -Zprint-type-sizes`. Install it:\r\n\r\n```\r\nrustup toolchain install nightly\r\n```\r\n\r\n### CI\r\n\r\n```yaml\r\n- name: Cache-line sanity check\r\n  run: |\r\n    rustup toolchain install nightly --profile minimal\r\n    cargo install cargo-snarf && cargo snarf\r\n```\r\n\r\nFor PR annotations without blocking:\r\n\r\n```yaml\r\n- name: Cache-line annotations\r\n  run: |\r\n    rustup toolchain install nightly --profile minimal\r\n    cargo install cargo-snarf && cargo snarf --format github --warn-only\r\n```\r\n\r\nThis repo runs snarf on itself — see [ci.yml](.github\u002Fworkflows\u002Fci.yml).\r\n\r\n### Options\r\n\r\n| Flag | What it does |\r\n|------|-------------|\r\n| `--strict` | Warn on all multi-field cache lines, not just contended ones |\r\n| `--format json` | Machine-readable output |\r\n| `--format github` | GitHub Actions annotations on the PR diff |\r\n| `--warn-only` | Report issues but exit 0 |\r\n| `--threshold N` | Minimum fields per line to warn (default: 2) |\r\n| `--line-size N` | Cache line size in bytes (default: 64, use 128 for Apple M-series) |\r\n| `--no-send-sync-check` | Warn even on `!Send`\u002F`!Sync` structs (see below) |\r\n| `--color never` | No ANSI escape codes |\r\n\r\nBy default snarf only warns when an `Atomic*`\u002F`Cell`\u002F`RefCell`\u002F`UnsafeCell` field shares a cache line with other fields. Detection is recursive, so `Option\u003CAtomicU64>` and `Arc\u003CMutex\u003CAtomicU64>>` are both caught. `--strict` warns on all multi-field lines regardless.\r\n\r\nStructs containing `!Send` or `!Sync` types (`Rc`, `Cell`, `RefCell`, raw pointers, lock guards) are automatically suppressed since they can't be shared across threads, making false sharing impossible. Suppressed structs print a note to stderr. Use `--no-send-sync-check` to disable this and warn on all structs.\r\n\r\n---\r\n\r\n### How it works\r\n\r\nParses structs with `syn`, then gets exact type sizes and field offsets from `cargo +nightly build -Zprint-type-sizes`. This resolves all types (custom structs, enums, non-repr(C) layouts, niche-optimized `Option`s) with no guessing.\r\n\r\n- All types resolved, including custom and cross-crate types\r\n- Non-repr(C) structs get exact field offsets from the compiler\r\n- Niche optimization (`Option\u003C&T>`, `Option\u003CNonZeroU64>`) handled correctly\r\n\r\n### Validation\r\n\r\nThe `validation\u002F` directory has a controlled experiment that correlates snarf's static warnings with real hardware cache-line contention measured by `perf c2c`. Two `#[repr(C)]` structs (one with co-located atomics, one with cache-line padding) are hammered from threads pinned to separate P-cores. The script runs snarf and `perf c2c`, then compares HITM event counts to snarf's warnings.\r\n\r\n```\r\ncd validation && .\u002Frun.sh   # requires sudo for perf c2c\r\n```\r\n\r\n### Limitations\r\n\r\n- `repr(packed)` not yet supported\r\n- Type name collisions: if two modules define a type with the same name (e.g. `a::Config` and `b::Config`), only the first is used (a warning is printed)\r\n\r\n### Name\r\n\r\n[snarf](http:\u002F\u002Fwww.catb.org\u002Fjargon\u002Fhtml\u002FS\u002Fsnarf.html) — hacker slang: to grab data greedily.\r\n\r\n### License\r\n\r\nMIT\r\n","snarf 是一个针对 Rust 结构体的缓存行误共享检测工具。其核心功能在于识别可能因原子操作或高竞争字段与其它字段共享同一缓存行而导致的潜在性能问题，但不直接验证运行时行为。通过解析结构体并利用 `cargo +nightly build -Zprint-type-sizes` 获取准确类型大小和字段偏移量，snarf 能够提供精确的布局分析。该工具特别适用于需要优化并发性能的场景，如多线程应用开发中，帮助开发者提前发现并解决因缓存行误共享引起的问题。此外，它还支持 CI 集成，方便在持续集成环境中自动化检查代码质量。","2026-06-11 04:06:56","CREATED_QUERY"]