Unverified Commit 94e2c32d authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

turbo-bitset: remove FixedBitSet and RoaringBitmap comparisons (#100724)

### What?
Removes the `FixedBitSet` and `RoaringBitmap` comparisons from the
`turbo-bitset` benchmarks and the `sizes` example.

- Every benchmark group now measures `Bitset` only. The persistence-path
`serialize` / `deserialize` and `hash_encode` benchmarks are unchanged.
- `sizes` reports `Bitset`'s in-memory and serialized sizes only.
- The `fixedbitset` and `roaring` dev-dependencies are removed from
`turbo-bitset`. `roaring` has no other user, so it is also removed from
the workspace and `Cargo.lock`. `fixedbitset` stays in the workspace for
its other users.
- The benchmark validation now checks `Bitset` against `BTreeSet`
reference sets, outside the timed code.

### Why?
The comparisons were for choosing the data structure. The design-choice
data stays in #100566. Keeping them in the regular benchmark suite
triples its runtime and keeps two dev-only dependencies around.

### How?
`Bitset`'s implementation is unchanged, so there are no new benchmark
numbers. The benchmarks still use the same inputs and persistence writer
and reader.

Stacked on #100630.


<!-- fleet b56269ed-2145-4f30-b0fe-dc9762520521 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent bba6e762
......@@ -6054,17 +6054,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "roaring"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18bd8a37d17a58532776dcdf6041ce64929adca78e8489d5cacbafe99229d3e1"
dependencies = [
"bytemuck",
"byteorder",
"serde",
]
[[package]]
name = "rstest"
version = "0.16.0"
......@@ -9068,9 +9057,7 @@ version = "0.1.0"
dependencies = [
"bincode",
"codspeed-criterion-compat",
"fixedbitset",
"rand 0.10.1",
"roaring",
"rustc-hash 2.1.1",
"shrink-to-fit",
"turbo-bincode",
......
......@@ -334,7 +334,6 @@ regex = "1.12.3"
regress = "0.11.1"
reqwest = { version = "0.13.2", default-features = false }
ringmap = "0.2.5"
roaring = "0.11.5"
rstest = "0.16.0"
rustc-hash = "2.1.1"
scattered-collect = "0.10.0"
......
......@@ -14,12 +14,8 @@ shrink-to-fit = { workspace = true }
[dev-dependencies]
criterion = { workspace = true }
fixedbitset = { workspace = true }
# The benchmark inputs are drawn from a seeded generator.
rand = { workspace = true }
# The benchmarks and the `sizes` example compare with `RoaringBitmap`, including its
# serialization through serde.
roaring = { workspace = true, features = ["serde"] }
rustc-hash = { workspace = true }
# The benchmarks and the `sizes` example encode, decode and hash like Turbopack does.
turbo-bincode = { workspace = true }
......
//! Measures the in-memory storage and serialized size of `Bitset` and `RoaringBitmap` for the
//! inputs of the benchmarks (see `benches/common/inputs.rs`).
//! Measures the in-memory storage and serialized size of `Bitset` for the inputs of the benchmarks
//! (see `benches/common/inputs.rs`).
//!
//! Storage is measured with a counting global allocator: the bytes requested from the allocator
//! by the set (its heap allocations), plus `size_of` the set itself. Allocator bookkeeping and
//! size-class rounding are not included.
//!
//! Serialized sizes are measured by actually encoding (and decoding again) with the writer, reader
//! and config Turbopack persists with (`turbo_bincode`, bincode's standard config):
//! - `Bitset` with its own encoding (the trimmed bitmap bytes, or the delta-encoded list of bits if
//! that is below 80% of the bitmap's size).
//! - `RoaringBitmap` through its serde implementation (the portable Roaring format as a
//! length-prefixed byte string), how Turbopack persisted these sets before `Bitset`.
//! and config Turbopack persists with (`turbo_bincode`, bincode's standard config), using
//! `Bitset`'s own encoding (the trimmed bitmap bytes, or the delta-encoded list of bits if that is
//! below 80% of the bitmap's size).
//!
//! Run with `cargo run --release -p turbo-bitset --example sizes`. Prints CSV.
......@@ -26,11 +24,7 @@ use std::{
};
use rand::seq::SliceRandom;
use roaring::RoaringBitmap;
use turbo_bincode::{
TURBO_BINCODE_CONFIG, TurboBincodeBuffer, TurboBincodeReader, TurboBincodeWriter,
turbo_bincode_decode, turbo_bincode_encode,
};
use turbo_bincode::{TURBO_BINCODE_CONFIG, turbo_bincode_decode, turbo_bincode_encode};
use turbo_bitset::Bitset;
use self::inputs::{SmallRng, inputs, rng};
......@@ -87,29 +81,10 @@ fn shuffled(rng: &mut SmallRng, bits: &[u32]) -> Vec<u32> {
bits
}
/// Encodes through serde with the writer and config Turbopack persists with.
fn encode_roaring(set: &RoaringBitmap) -> TurboBincodeBuffer {
let mut buffer = TurboBincodeBuffer::new();
bincode::serde::encode_into_writer(
set,
TurboBincodeWriter::new(&mut buffer),
TURBO_BINCODE_CONFIG,
)
.unwrap();
buffer
}
/// Decodes through serde with the reader and config Turbopack persists with.
fn decode_roaring(bytes: &[u8]) -> RoaringBitmap {
bincode::serde::decode_from_reader(TurboBincodeReader::new(bytes), TURBO_BINCODE_CONFIG)
.unwrap()
}
fn main() {
println!(
"input,universe,bits,density_ppm,bitset_sorted,bitset_random,roaring_sorted,\
roaring_random,bitset_words,bitset_ser,bitset_form,roaring_portable,roaring_ser,\
roaring_ser_optimized"
"input,universe,bits,density_ppm,bitset_sorted,bitset_random,bitset_words,bitset_ser,\
bitset_form"
);
let mut rng = rng(7);
for input in inputs() {
......@@ -125,18 +100,8 @@ fn main() {
}
set
});
let (roaring_sorted, roaring_sorted_bytes) =
storage(|| RoaringBitmap::from_sorted_iter(bits.iter().copied()).unwrap());
let (roaring_random, roaring_random_bytes) = storage(|| {
let mut set = RoaringBitmap::new();
for &bit in &random_order {
set.insert(bit);
}
set
});
assert_eq!(bitset_sorted, bitset_random);
assert_eq!(roaring_sorted, roaring_random);
assert!(bitset_sorted.iter().eq(roaring_sorted.iter()));
assert!(bitset_sorted.iter().eq(bits.iter().copied()));
// The block-aligned word range of the set: from the lowest to the highest word.
let words = match (bits.first(), bits.last()) {
......@@ -156,32 +121,15 @@ fn main() {
_ => "bitmap",
};
// The portable Roaring format, and the same through bincode's serde support.
let mut portable = Vec::new();
roaring_sorted.serialize_into(&mut portable).unwrap();
assert_eq!(portable.len(), roaring_sorted.serialized_size());
let roaring_ser = encode_roaring(&roaring_sorted);
assert_eq!(decode_roaring(&roaring_ser), roaring_sorted);
let mut optimized = roaring_sorted.clone();
optimized.optimize();
let optimized_ser = encode_roaring(&optimized);
assert_eq!(decode_roaring(&optimized_ser), roaring_sorted);
println!(
"{},{},{},{},{bitset_sorted_bytes},{bitset_random_bytes},{roaring_sorted_bytes},\
{roaring_random_bytes},{words},{},{bitset_form},{},{},{}",
"{},{},{},{},{bitset_sorted_bytes},{bitset_random_bytes},{words},{},{bitset_form}",
input.name,
input.universe,
bits.len(),
bits.len() as u64 * 1_000_000 / input.universe as u64,
bitset_ser.len(),
portable.len(),
roaring_ser.len(),
optimized_ser.len(),
);
check_freed(bitset_sorted, bitset_sorted_bytes);
check_freed(bitset_random, bitset_random_bytes);
check_freed(roaring_sorted, roaring_sorted_bytes);
check_freed(roaring_random, roaring_random_bytes);
}
}
......@@ -6,9 +6,9 @@
//! allocate the empty blocks below them. Like a `Vec`, the storage grows with amortized growth,
//! at the front as well as at the back.
//!
//! Compared to a `RoaringBitmap`, which is optimized for compact storage, every operation is a
//! simple loop over machine words. That makes unions and subset checks fast when the bits span a
//! limited range, at the cost of using one bit of memory per index in that range.
//! Every operation is a simple loop over machine words. That makes unions and subset checks fast
//! when the bits span a limited range, at the cost of using one bit of memory per index in that
//! range.
//!
//! The bincode encoding (see the `encode` module) stores either the trimmed bytes of the range or,
//! if that is clearly smaller, the delta-encoded list of bits, so sparse sets stay compact when
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment