Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Remove index GAT #65

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ A flat container for Rust.

```toml
[dependencies]
flatcontainer = "0.4"
flatcontainer = "0.6"
```

## Example

```rust
use flatcontainer::FlatStack;
use flatcontainer::{Index, Push, RegionPreference};

let r: Result<_, u16> = Ok("abc");
let mut c = FlatStack::default_impl::<Result<&str, u16>>();
c.copy(&r);
assert_eq!(r, c.get(0));
let mut c = <<Result<&str, u16> as RegionPreference>::Region>::default();
c.push(&r);
assert_eq!(Ok("abc"), c.index(0));
```

## Details
Expand Down
146 changes: 74 additions & 72 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! A simple benchmark for flatcontainer, adopted from `columnation`'s benchmark.

use codspeed_bencher_compat::{benchmark_group, benchmark_main, Bencher};
use flatcontainer::impls::deduplicate::{CollapseSequence, ConsecutiveIndexPairs};
use flatcontainer::impls::index::IndexOptimized;
use flatcontainer::impls::tuple::{TupleABCRegion, TupleABRegion};
use flatcontainer::{
ColumnsRegion, FlatStack, MirrorRegion, OwnedRegion, Push, Region, RegionPreference,
ReserveItems, SliceRegion, StringRegion,
Clear, HeapSize, Index, OwnedRegion, Push, RegionPreference, ReserveItems, SliceRegion,
StringRegion,
};

fn empty_copy(bencher: &mut Bencher) {
Expand Down Expand Up @@ -64,50 +62,50 @@ fn str100_copy_region(bencher: &mut Bencher) {
fn string10_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<StringRegion>, _>(bencher, vec![format!("grawwwwrr!"); 1024]);
}
fn string10_copy_region_collapse(bencher: &mut Bencher) {
_bench_copy_region::<
SliceRegion<CollapseSequence<ConsecutiveIndexPairs<StringRegion>>, IndexOptimized>,
_,
>(bencher, vec![format!("grawwwwrr!"); 1024]);
}
// fn string10_copy_region_collapse(bencher: &mut Bencher) {
// _bench_copy_region::<
// SliceRegion<CollapseSequence<ConsecutiveIndexPairs<StringRegion>>, IndexOptimized>,
// _,
// >(bencher, vec![format!("grawwwwrr!"); 1024]);
// }
fn string20_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<StringRegion>, _>(
bencher,
vec![format!("grawwwwrr!!!!!!!!!!!"); 512],
);
}
fn vec_u_s_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<SliceRegion<SliceRegion<TupleABRegion<MirrorRegion<_>, StringRegion>>>, _>(
_bench_copy_region::<SliceRegion<SliceRegion<TupleABRegion<Vec<u64>, StringRegion>>>, _>(
bencher,
vec![vec![(0u64, "grawwwwrr!".to_string()); 32]; 32],
);
}
fn vec_u_vn_s_copy_region(bencher: &mut Bencher) {
_bench_copy_region::<
SliceRegion<SliceRegion<TupleABCRegion<MirrorRegion<_>, OwnedRegion<_>, StringRegion>>>,
_,
>(
bencher,
vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
);
}
fn vec_u_vn_s_copy_region_column(bencher: &mut Bencher) {
_bench_copy_region::<
SliceRegion<
ColumnsRegion<
TupleABCRegion<
MirrorRegion<_>,
CollapseSequence<OwnedRegion<_>>,
CollapseSequence<StringRegion>,
>,
>,
>,
SliceRegion<SliceRegion<TupleABCRegion<Vec<u64>, OwnedRegion<()>, StringRegion>>>,
_,
>(
bencher,
vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
);
}
// fn vec_u_vn_s_copy_region_column(bencher: &mut Bencher) {
// _bench_copy_region::<
// SliceRegion<
// ColumnsRegion<
// TupleABCRegion<
// MirrorRegion<_>,
// CollapseSequence<OwnedRegion<_>>,
// CollapseSequence<StringRegion>,
// >,
// >,
// >,
// _,
// >(
// bencher,
// vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
// );
// }

fn empty_clone(bencher: &mut Bencher) {
_bench_clone(bencher, vec![(); 1024]);
Expand Down Expand Up @@ -276,37 +274,37 @@ fn string20_copy_flat_region(bencher: &mut Bencher) {
);
}
fn vec_u_s_copy_flat_region(bencher: &mut Bencher) {
_bench_copy_flat::<SliceRegion<SliceRegion<TupleABRegion<MirrorRegion<_>, StringRegion>>>, _>(
_bench_copy_flat::<SliceRegion<SliceRegion<TupleABRegion<Vec<u64>, StringRegion>>>, _>(
bencher,
vec![vec![(0u64, "grawwwwrr!".to_string()); 32]; 32],
);
}
fn vec_u_vn_s_copy_flat_region(bencher: &mut Bencher) {
_bench_copy_flat::<
SliceRegion<SliceRegion<TupleABCRegion<MirrorRegion<_>, OwnedRegion<_>, StringRegion>>>,
_,
>(
bencher,
vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
);
}
fn vec_u_vn_s_copy_flat_region_column(bencher: &mut Bencher) {
_bench_copy_flat::<
SliceRegion<
ColumnsRegion<
TupleABCRegion<
MirrorRegion<_>,
CollapseSequence<OwnedRegion<_>>,
CollapseSequence<StringRegion>,
>,
>,
>,
SliceRegion<SliceRegion<TupleABCRegion<Vec<u64>, OwnedRegion<()>, StringRegion>>>,
_,
>(
bencher,
vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
);
}
// fn vec_u_vn_s_copy_flat_region_column(bencher: &mut Bencher) {
// _bench_copy_flat::<
// SliceRegion<
// ColumnsRegion<
// TupleABCRegion<
// MirrorRegion<_>,
// CollapseSequence<OwnedRegion<_>>,
// CollapseSequence<StringRegion>,
// >,
// >,
// >,
// _,
// >(
// bencher,
// vec![vec![(0u64, vec![(); 1 << 40], "grawwwwrr!".to_string()); 32]; 32],
// );
// }

fn set_bytes(target: &mut u64, bytes: usize) {
if std::env::var("BYTES").is_ok() {
Expand All @@ -316,15 +314,15 @@ fn set_bytes(target: &mut u64, bytes: usize) {

fn _bench_copy<T: RegionPreference + Eq>(bencher: &mut Bencher, record: T)
where
for<'a> <T as RegionPreference>::Region: Push<&'a T>,
for<'a> <T as RegionPreference>::Region: Default + HeapSize + Clear + Push<&'a T>,
{
// prepare encoded data for bencher.bytes
let mut arena = FlatStack::default_impl::<T>();
let mut arena = T::Region::default();

bencher.iter(|| {
arena.clear();
for _ in 0..1024 {
arena.copy(&record);
arena.push(&record);
}
});
let (mut siz, mut cap) = (0, 0);
Expand All @@ -335,17 +333,17 @@ where
set_bytes(&mut bencher.bytes, siz);
}

fn _bench_copy_region<R: Region, T>(bencher: &mut Bencher, record: T)
fn _bench_copy_region<R, T>(bencher: &mut Bencher, record: T)
where
for<'a> R: Push<&'a T>,
for<'a> R: Default + HeapSize + Clear + Push<&'a T>,
{
// prepare encoded data for bencher.bytes
let mut arena = FlatStack::<R>::default();
let mut arena = R::default();

bencher.iter(|| {
arena.clear();
for _ in 0..1024 {
arena.copy(&record);
arena.push(&record);
}
});
let (mut siz, mut cap) = (0, 0);
Expand All @@ -370,14 +368,14 @@ fn _bench_clone<T: RegionPreference + Eq + Clone>(bencher: &mut Bencher, record:

fn _bench_realloc<T: RegionPreference + Eq>(bencher: &mut Bencher, record: T)
where
for<'a> <T as RegionPreference>::Region: Push<&'a T>,
for<'a> <T as RegionPreference>::Region: Default + HeapSize + Push<&'a T>,
{
let mut arena = FlatStack::default_impl::<T>();
let mut arena = T::Region::default();
bencher.iter(|| {
// prepare encoded data for bencher.bytes
arena = FlatStack::default_impl::<T>();
arena = T::Region::default();
for _ in 0..1024 {
arena.copy(&record);
arena.push(&record);
}
});
let (mut siz, mut cap) = (0, 0);
Expand All @@ -389,15 +387,15 @@ where

fn _bench_prealloc<T: RegionPreference + Eq>(bencher: &mut Bencher, record: T)
where
for<'a> <T as RegionPreference>::Region: ReserveItems<&'a T> + Push<&'a T>,
for<'a> <T as RegionPreference>::Region: Default + HeapSize + ReserveItems<&'a T> + Push<&'a T>,
{
let mut arena = FlatStack::default_impl::<T>();
let mut arena = T::Region::default();
bencher.iter(|| {
arena = FlatStack::default_impl::<T>();
arena = T::Region::default();
// prepare encoded data for bencher.bytes
arena.reserve_items(std::iter::repeat(&record).take(1024));
for _ in 0..1024 {
arena.copy(&record);
arena.push(&record);
}
});
let (mut siz, mut cap) = (0, 0);
Expand All @@ -411,22 +409,26 @@ where
fn _bench_copy_flat_preference<T>(bencher: &mut Bencher, record: T)
where
T: RegionPreference,
for<'a> <T as RegionPreference>::Region:
Push<&'a T> + Push<<<T as RegionPreference>::Region as Region>::ReadItem<'a>> + Clone,
for<'a> <T as RegionPreference>::Region: Default
+ Index
+ HeapSize
+ Push<&'a T>
+ Push<<<T as RegionPreference>::Region as Index>::ReadItem<'a>>
+ Clone,
{
_bench_copy_flat::<T::Region, T>(bencher, record)
}

fn _bench_copy_flat<R, T>(bencher: &mut Bencher, record: T)
where
for<'a> R: Region + Push<&'a T> + Push<<R as Region>::ReadItem<'a>> + Clone,
for<'a> R: Default + Index + HeapSize + Push<&'a T> + Push<<R as Index>::ReadItem<'a>> + Clone,
{
// prepare encoded data for bencher.bytes
let mut arena = FlatStack::<R>::default();
let mut arena = R::default();
for _ in 0..1024 {
arena.copy(&record);
arena.push(&record);
}
let mut target = FlatStack::<R>::default();
let mut target = R::default();

bencher.iter(|| {
target.clone_from(&arena);
Expand Down Expand Up @@ -486,7 +488,7 @@ benchmark_group!(
str10_copy_region,
string10_copy_flat_region,
string10_copy_region,
string10_copy_region_collapse,
// string10_copy_region_collapse,
string20_copy_flat_region,
string20_copy_region,
u32x2_copy_flat_region,
Expand All @@ -498,9 +500,9 @@ benchmark_group!(
vec_u_s_copy_flat_region,
vec_u_s_copy_region,
vec_u_vn_s_copy_flat_region,
vec_u_vn_s_copy_flat_region_column,
// vec_u_vn_s_copy_flat_region_column,
vec_u_vn_s_copy_region,
vec_u_vn_s_copy_region_column,
// vec_u_vn_s_copy_region_column,
);
benchmark_group!(
alloc,
Expand Down
Loading
Loading