Skip to content

pjullrich/f_enum

Back Optimize Rust NIFs for speed and prepare for hex publishing

Commit details

Optimize Rust NIFs for speed and prepare for hex publishing

Description

Key performance improvements: - Replace RwLock<Vec<i64>> with lock-free Box<[i64]> for resource storage. Data is immutable after creation, so the atomic CAS on every read was pure overhead. - Replace std HashMap/HashSet (SipHash) with FxHash (rustc-hash crate) for frequencies and uniq. FxHash uses a fast multiply+xor instead of cryptographic hashing. Result: uniq 4x faster on lists, 6x on binaries. - Zero-copy binary reads for aggregations (sum, min, max, member?, etc). Previously copied the entire binary into a Vec just to iterate. Now reinterprets bytes in-place via as_i64_slice! macro. Result: sum(binary) 2.3x faster, min/max 1.8x faster. - Replace write!("{}", v) with itoa crate for join operations (~3x faster integer-to-string conversion). - Single-pass minmax instead of two separate .min() + .max() iterations. - Cache-friendly reverse: memcpy + in-place swap instead of backwards reads that cause prefetcher misses on large arrays. - Single-pass dedup for chain mode: scan directly into output Vec instead of clone + compact. - Raw pointer writes for with_index/zip to enable auto-vectorization (push() loop inhibits SIMD due to per-element capacity checks). - get_unchecked for at/zip where bounds are already validated. - Pre-sized HashMap/HashSet/Vec/String with_capacity throughout. - Cargo.toml: lto = "fat", codegen-units = 1 for maximum link-time optimization. - Add ex_doc, hex package metadata, and scaling benchmark suite.

Metadata

Author
Peter Ullrich PJUllrich@users.noreply.github.com
Committed
Commit

Contributors

  • Peter Ullrich PJUllrich@users.noreply.github.com Author
  • Claude Opus 4.6 (1M context) noreply@anthropic.com Co-author