Skip to content

v2.1: Packing Cows 🐮

Choose a tag to compare

@github-actions github-actions released this 06 Oct 15:06
· 28 commits to main since this release

The StringTape crate now also provides "Cows" classes for large arrays of references pointing into parent Copy-On-Write objects, allowing for the handling of larger datasets. Why? In addition to storing 3 pointers for every String instance, you often need another 2-4 pointers per entry in your heap. Assuming most English words are under 8 bytes long, storing an extra 6 pointers on a 64-bit machine results in a 7x memory usage amplification. So choose your data structures wisely!

let doc = fs::read_to_string("enwik9.txt")?;    // 1.0 GB
let words = doc.split_whitespace();             // ~ 160 M words
let buffers = words.map(str::as_bytes);

let _ = Vec::<String>::from_iter(words);        // + 7.1 GB copied ❌
let _ = CharsTapeAuto::from_iter(words);        // + 1.3 GB copied ✅
let _ = Vec::<&[u8]>::from_iter(buffers);       // + 1.9 GB copy-less ⚠️
let _ = BytesCowsAuto::from_iter_and_data(      // + 0.7 GB copy-less ✅
    buffers,
    Cow::Borrowed(doc.as_bytes()),
);

Minor

Patch

  • Improve: Funnier naming - Cows FTW 🐮 (78d500e)
  • Improve: Allocators for reorderable classes (76c906d)
  • Docs: Cleaner explanations (86b4ed2)