12 releases (5 breaking)

0.7.0 May 9, 2025
0.6.1 Mar 27, 2025
0.5.4 Feb 19, 2025
0.4.1 Feb 4, 2025
0.1.0 Aug 23, 2024

#244 in Data structures

Download history 371/week @ 2025-01-29 1250/week @ 2025-02-05 796/week @ 2025-02-12 1281/week @ 2025-02-19 1073/week @ 2025-02-26 801/week @ 2025-03-05 727/week @ 2025-03-12 1093/week @ 2025-03-19 1709/week @ 2025-03-26 1391/week @ 2025-04-02 1292/week @ 2025-04-09 1320/week @ 2025-04-16 4572/week @ 2025-04-23 4609/week @ 2025-04-30 3665/week @ 2025-05-07 3137/week @ 2025-05-14

16,308 downloads per month
Used in 31 crates (5 directly)

MIT/Apache

53KB
1.5K SLoC

byteview

CI CI docs.rs Crates.io MSRV

An immutable byte slice that may be inlined, and can be partially cloned without heap allocation.

Think of it as a specialized Arc<[u8]> that can be inlined (skip allocation for small values) and no weak count.

Memory layout

byteview was designed to speed up deserialization in lsm-tree, allow inlining of small values and reduce memory usage compared to Arc'd slices. Values with a known length can be constructed 2-2.5x faster than using Arc<[u8]>:

Constructor benchmark

Memory usage

Allocating 200M "" (len=0) strings:

Struct Memory Usage
Arc<[u8]> 9.6 GB
tokio::Bytes 6.4 GB
ByteView 4.8 GB

Allocating 200M "helloworld" (len=10) strings:

Struct Memory Usage
Arc<[u8]> 12.8 GB
tokio::Bytes 12.8 GB
ByteView 4.8 GB

Allocating 100M "helloworldhelloworld" (len=20) strings:

Struct Memory Usage
Arc<[u8]> 6.4 GB
tokio::Bytes 6.4 GB
ByteView 2.4 GB

Allocating 50M "helloworldhelloworldhelloworldhelloworld" (len=30) strings:

Struct Memory Usage
Arc<[u8]> 4.0 GB
tokio::Bytes 4.0 GB
ByteView 3.6 GB

Allocating 500k "helloworld".repeat(1000) (len=10'000) strings:

Struct Memory Usage
Arc<[u8]> 5 GB
tokio::Bytes 5 GB
ByteView 5 GB

Run fuzz tests

cargo +nightly fuzz run fuzz_target_1

Dependencies

~150KB