Overview of Slice 2.0
masterlong) at specific indices without manual byte assembly. It also supports bulk data transfers between byte arrays and primitive arrays.repository·master·Indexed 19 days ago
https://github.com/airlift/sliceA high-performance Java library for efficient byte array manipulation. Slice 2.0 provides fast access to primitives using little-endian byte order via VarHandles and MemorySegment, bulk data transfers, and specialized utilities for UTF-8 encoded data and IO streams.
long) at specific indices without manual byte assembly. It also supports bulk data transfers between byte arrays and primitive arrays.InputStream and OutputStream. These classes inherit the same performance characteristics as the core Slice class, allowing for fast single-primitive access and bulk data transfers directly through IO streams.Slice provides a dedicated library for processing UTF-8 encoded data stored within byte arrays. You can use these utilities to perform common string-like operations directly on the bytes, including:
Slice 2.0 uses little-endian byte order for storing multi-byte values.
This design ensures data consistency regardless of the host CPU's endianness. While previous versions relied on sun.misc.Unsafe (which could cause corruption on big-endian CPUs), Slice 2.0 uses VarHandles and MemorySegment to explicitly specify little-endian order. This allows the library to work correctly on any CPU architecture by transparently handling byte swapping when necessary.
Note that hash functions like XxHash64 and Murmur3 also follow this little-endian specification.
If your project requires support for off-heap memory or the ability to be backed by any Java primitive array type, you must use a version of Slice prior to 2.0. These features were removed in version 2.0 to simplify the codebase.
Legacy versions are available on the release-0.x branch.
The MemoryCopyBenchmark measures the throughput of different memory copy strategies used in Slice. Throughput is measured in ops/ms (operations per millisecond), where higher numbers indicate better performance.
The benchmarks compare three primary methods across various payload sizes (from 0 to 128MB):
unsafe operations.Use these results to understand how Slice's performance scales with different data sizes and to compare its efficiency against manual or unsafe alternatives on specific hardware architectures.