#cache #optimization #architecture #no-std #cache-optimizations

no-std cuneiform-fields

Field level [no_std] cache optimizations for Rust

3 unstable releases

0.1.1 Feb 3, 2021
0.1.0 Dec 31, 2019
0.0.0 Dec 29, 2019

#440 in Concurrency

Download history 45/week @ 2024-03-11 16/week @ 2024-03-18 19/week @ 2024-03-25 61/week @ 2024-04-01 18/week @ 2024-04-08 41/week @ 2024-04-15 52/week @ 2024-04-22 71/week @ 2024-04-29 37/week @ 2024-05-06 37/week @ 2024-05-13 30/week @ 2024-05-20 22/week @ 2024-05-27 36/week @ 2024-06-03 29/week @ 2024-06-10 23/week @ 2024-06-17 20/week @ 2024-06-24

110 downloads per month
Used in 4 crates (3 directly)

Apache-2.0/MIT

12KB
169 lines

Field level cache optimizations for Rust (no_std)

Build Status Latest Version Rust Documentation

This crate provides cache line size fitting optimizations to fields in structs.

This crate aligns fields with #[repr(align(COHERENCE_LINE_SIZE))] to decrease the time between prefetch signals for data. COHERENCE_LINE_SIZE can be detected or decided based on the architecture by cuneiform itself.

[dependencies]
cuneiform-fields = "0.1"

Examples

Hermetic aligned fields

Align by hermetic cache line size detection mentioned in cuneiform readme:

use cuneiform_fields::prelude::*;

pub struct Hermetic {
    data: HermeticPadding<u8>,
    data_2: u16,
}

In the example above data will be aligned by hermetic alignment but field data_2 isn't going to be alignment optimized.

Architecture aligned fields

Align by cache line size detected by current Rust compiler architecture. If architecture isn't detected in known architectures it will fall back to default alignment:

use cuneiform_fields::prelude::*;

pub struct ArchSpecific {
    data: ArchPadding<u8>,
    data_2: u16,
}

In the example above data will be aligned by architecture alignment but field data_2 isn't going to be alignment optimized.

NOTE: Alignment values are not randomly chosen or incorporated directly. Values are considered and incorporated inside with the mindset of preventing false sharing or creating less warp points in exclusive caching.

For design choices, architecture and board systems and more information. Please visit Cuneiform GitHub.

Dependencies

~1.3–8.5MB
~75K SLoC