Skip to content

Commit

Permalink
Remove FlexZeroVec
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 1, 2024
1 parent 79d1183 commit 81f3f21
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 1,929 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- Change the `VarZeroVecFormat` values shipped by default to use the same index and length width. This breaks data layout for all `VarZeroVec`s. (https://github.com/unicode-org/icu4x/pull/5594)
- Change the `VarZeroVec` format to not store a superfluous 0 index at the beginning of the index array. This breaks data layout for all `VarZeroVec`s (https://github.com/unicode-org/icu4x/pull/5601)
- Optimize `MultiFieldsULE` to not store a length anymore. This breaks data layout for any `#[make_varule]`-using struct with multiple variable-sized fields. (https://github.com/unicode-org/icu4x/pull/5593)
- Remove `FlexZeroVec` (https://github.com/unicode-org/icu4x/pull/5604)
- `writeable`


Expand Down
2 changes: 1 addition & 1 deletion utils/potential_utf/src/ustr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use core::ops::Deref;
/// use zerovec::ZeroMap;
///
/// // This map is cheap to deserialize, as we don't need to perform UTF-8 validation.
/// let map: ZeroMap<PotentialUtf8, usize> = [
/// let map: ZeroMap<PotentialUtf8, u8> = [
/// (PotentialUtf8::from_bytes(b"abc"), 11),
/// (PotentialUtf8::from_bytes(b"def"), 22),
/// (PotentialUtf8::from_bytes(b"ghi"), 33),
Expand Down
44 changes: 6 additions & 38 deletions utils/zerotrie/benches/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ fn get_basic_bench(c: &mut Criterion) {

#[cfg(feature = "bench")]
g.bench_function("ZeroMap/usize", |b| {
let zm: ZeroMap<[u8], usize> = data.iter().copied().collect();
let zm: ZeroMap<[u8], u32> = data.iter().map(|(a, b)| (*a, *b as u32)).collect();
b.iter(|| {
for (key, expected) in black_box(data) {
let actual = black_box(&zm).get_copied(key);
assert_eq!(Some(*expected), actual);
assert_eq!(Some(*expected as u32), actual);
}
});
});
Expand All @@ -88,22 +88,6 @@ fn get_basic_bench(c: &mut Criterion) {
});
});

#[cfg(feature = "bench")]
g.bench_function("ZeroHashMap/usize", |b| {
let zhm: ZeroHashMap<[u8], usize> = data
.iter()
.copied()
.collect();
b.iter(|| {
for (key, expected) in black_box(data) {
let actual = black_box(&zhm).get(key);
// No get_copied on ZHM so we need to do it manually
let actual = actual.map(|x| <zerovec::vecs::FlexZeroSlice as zerovec::maps::ZeroVecLike<usize>>::zvl_get_as_t(x, |y| *y));
assert_eq!(Some(*expected), actual);
}
});
});

#[cfg(feature = "bench")]
g.bench_function("ZeroHashMap/u8", |b| {
let zhm: ZeroHashMap<[u8], u8> = data.iter().map(|(k, v)| (*k, *v as u8)).collect();
Expand Down Expand Up @@ -171,11 +155,11 @@ fn get_subtags_bench_helper<M: criterion::measurement::Measurement>(

#[cfg(feature = "bench")]
g.bench_function("ZeroMap/usize", |b| {
let zm: ZeroMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zm: ZeroMap<[u8], u32> = litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
b.iter(|| {
for (i, key) in black_box(strings).iter().enumerate() {
let actual = black_box(&zm).get_copied(key.as_bytes());
assert_eq!(Some(i), actual);
assert_eq!(Some(i as u32), actual);
}
});
});
Expand All @@ -193,27 +177,11 @@ fn get_subtags_bench_helper<M: criterion::measurement::Measurement>(

#[cfg(feature = "bench")]
g.bench_function("HashMap", |b| {
let hm: HashMap<&[u8], usize> = litemap.iter().map(|(a, b)| (*a, *b)).collect();
let hm: HashMap<&[u8], u32> = litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
b.iter(|| {
for (i, key) in black_box(strings).iter().enumerate() {
let actual = black_box(&hm).get(key.as_bytes());
assert_eq!(Some(&i), actual);
}
});
});

#[cfg(feature = "bench")]
g.bench_function("ZeroHashMap/usize", |b| {
let zhm: ZeroHashMap<[u8], usize> = litemap
.iter()
.map(|(a, b)| (*a, b))
.collect();
b.iter(|| {
for (i, key) in black_box(strings).iter().enumerate() {
let actual = black_box(&zhm).get(key.as_bytes());
// No get_copied on ZHM so we need to do it manually
let actual = actual.map(|x| <zerovec::vecs::FlexZeroSlice as zerovec::maps::ZeroVecLike<usize>>::zvl_get_as_t(x, |y| *y));
assert_eq!(Some(i), actual);
assert_eq!(Some(i as u32), actual.copied());
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions utils/zerotrie/tests/asciitrie_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_basic() {
}

// Compare the size to a postcard ZeroMap
let zm: ZeroMap<[u8], usize> = data_ascii.iter().copied().collect();
let zm: ZeroMap<[u8], u32> = data_ascii.iter().map(|(a, b)| (*a, *b as u32)).collect();
let mut serializer = postcard::Serializer {
output: AllocVec::new(),
};
Expand All @@ -69,5 +69,5 @@ fn test_basic() {
.expect("Failed to finalize serializer output");

assert_eq!(26, bytes_ascii.len());
assert_eq!(57, zeromap_bytes.len());
assert_eq!(77, zeromap_bytes.len());
}
39 changes: 21 additions & 18 deletions utils/zerotrie/tests/builder_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,21 +648,22 @@ fn test_everything() {
assert_bytes_eq!(36, trie_phf.as_bytes(), expected_bytes);
check_phf_ascii_trie(&litemap, &trie_phf);

let zhm: zerovec::ZeroMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zhm: zerovec::ZeroMap<[u8], u32> = litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 71);
assert_eq!(zhm_buf.len(), 88);

let zhm: zerovec::ZeroMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 61);
assert_eq!(zhm_buf.len(), 63);

let zhm: zerovec::ZeroHashMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zhm: zerovec::ZeroHashMap<[u8], u32> =
litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 144);
assert_eq!(zhm_buf.len(), 161);

let zhm: zerovec::ZeroHashMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 134);
assert_eq!(zhm_buf.len(), 136);
}

macro_rules! utf8_byte {
Expand Down Expand Up @@ -804,21 +805,22 @@ fn test_short_subtags_10pct() {
assert_eq!(trie_phf.byte_len(), 1100);
check_phf_ascii_trie(&litemap, &trie_phf);

let zhm: zerovec::ZeroMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zhm: zerovec::ZeroMap<[u8], u32> = litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 1327);
assert_eq!(zhm_buf.len(), 1890);

let zhm: zerovec::ZeroMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 1326);
assert_eq!(zhm_buf.len(), 1328);

let zhm: zerovec::ZeroHashMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zhm: zerovec::ZeroHashMap<[u8], u32> =
litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 2833);
assert_eq!(zhm_buf.len(), 3396);

let zhm: zerovec::ZeroHashMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 2832);
assert_eq!(zhm_buf.len(), 2834);
}

#[test]
Expand All @@ -834,19 +836,20 @@ fn test_short_subtags() {
assert_eq!(trie_phf.byte_len(), 9400);
check_phf_ascii_trie(&litemap, &trie_phf);

let zm: zerovec::ZeroMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zm: zerovec::ZeroMap<[u8], u32> = litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zm).unwrap();
assert_eq!(zhm_buf.len(), 15178);
assert_eq!(zhm_buf.len(), 18931);

let zm: zerovec::ZeroMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zm).unwrap();
assert_eq!(zhm_buf.len(), 13300);
assert_eq!(zhm_buf.len(), 13302);

let zhm: zerovec::ZeroHashMap<[u8], usize> = litemap.iter().map(|(a, b)| (*a, b)).collect();
let zhm: zerovec::ZeroHashMap<[u8], u32> =
litemap.iter().map(|(a, b)| (*a, *b as u32)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 30196);
assert_eq!(zhm_buf.len(), 33949);

let zhm: zerovec::ZeroHashMap<[u8], u8> = litemap.iter().map(|(a, b)| (*a, *b as u8)).collect();
let zhm_buf = postcard::to_allocvec(&zhm).unwrap();
assert_eq!(zhm_buf.len(), 28318);
assert_eq!(zhm_buf.len(), 28320);
}
78 changes: 0 additions & 78 deletions utils/zerovec/src/flexzerovec/databake.rs

This file was deleted.

20 changes: 0 additions & 20 deletions utils/zerovec/src/flexzerovec/mod.rs

This file was deleted.

Loading

0 comments on commit 81f3f21

Please sign in to comment.