Skip to content

Commit

Permalink
fixed bench
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Sep 27, 2023
1 parent 79f8334 commit 6bef9c9
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion grovedb/src/operations/proof/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl ProofVerifier {
query: &PathQuery,
is_verbose: bool,
) -> Result<[u8; 32], Error> {
let (proof_version, proof) = read_and_consume_proof_version(proof)?;
let (_proof_version, proof) = read_and_consume_proof_version(proof)?;
let mut proof_reader = ProofReader::new_with_verbose_status(proof, is_verbose);

let path_slices = query.path.iter().map(|x| x.as_slice()).collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion grovedb/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,7 @@ fn test_tree_value_exists_method_tx() {
#[test]
fn test_storage_wipe() {
let db = make_test_grovedb();
let path = db._tmp_dir.path();
let _path = db._tmp_dir.path();

// Test keys in non-root tree
db.insert(
Expand Down
8 changes: 4 additions & 4 deletions grovedb/src/versioning.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io::Cursor;

use integer_encoding::{VarInt, VarIntReader, VarIntWriter};
use integer_encoding::{VarInt, VarIntReader};

use crate::{Error, Error::InternalError};
use crate::Error;

pub(crate) const PROOF_VERSION: u32 = 1;

Expand Down Expand Up @@ -44,11 +44,11 @@ mod tests {

#[test]
fn read_correct_version() {
let mut data = vec![1, 2, 3];
let data = vec![1, 2, 3];
let version = 500_u32;

// prepend the version information to the data vector
let mut new_data = prepend_version_to_bytes(data, version).unwrap();
let new_data = prepend_version_to_bytes(data, version).unwrap();
assert_eq!(new_data, [244, 3, 1, 2, 3]);

// show that read_version doesn't consume
Expand Down
68 changes: 48 additions & 20 deletions merk/benches/merk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use grovedb_costs::storage_cost::removal::StorageRemovedBytes::BasicStorageRemoval;
use grovedb_merk::{
proofs,
test_utils::{make_batch_rand, make_batch_seq, make_del_batch_rand, TempMerk},
tree::kv::ValueDefinedCostType,
Merk,
};
use grovedb_path::SubtreePath;
use grovedb_storage::{rocksdb_storage::test_utils::TempStorage, Storage};
use merk::{proofs::encode_into as encode_proof_into, test_utils::*, Merk};
use rand::prelude::*;

/// 1 million gets in 2k batches
Expand All @@ -46,11 +51,12 @@ pub fn get(c: &mut Criterion) {
let mut batches = vec![];
for i in 0..num_batches {
let batch = make_batch_rand(batch_size, i);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -72,7 +78,9 @@ pub fn get(c: &mut Criterion) {
let key_index = (i / num_batches) as usize;

let key = &batches[batch_index][key_index].0;
merk.get(key, true).unwrap().expect("get failed");
merk.get(key, true, None::<fn(&[u8]) -> Option<ValueDefinedCostType>>)
.unwrap()
.expect("get failed");

i = (i + 1) % initial_size;
})
Expand All @@ -98,11 +106,12 @@ pub fn insert_1m_2k_seq(c: &mut Criterion) {

b.iter_with_large_drop(|| {
let batch = &batches[i % n_batches];
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -137,11 +146,12 @@ pub fn insert_1m_2k_rand(c: &mut Criterion) {

b.iter_with_large_drop(|| {
let batch = &batches[i % n_batches];
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -169,11 +179,12 @@ pub fn update_1m_2k_seq(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_seq(((i * batch_size) as u64)..((i + 1) * batch_size) as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -193,11 +204,12 @@ pub fn update_1m_2k_seq(c: &mut Criterion) {

b.iter_with_large_drop(|| {
let batch = &batches[i % n_batches];
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -225,11 +237,12 @@ pub fn update_1m_2k_rand(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -249,11 +262,12 @@ pub fn update_1m_2k_rand(c: &mut Criterion) {

b.iter_with_large_drop(|| {
let batch = &batches[i % n_batches];
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -283,11 +297,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) {
for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
let delete_batch = make_del_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -311,11 +326,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) {

// Merk tree is kept with 1m elements before each bench iteration for more or
// less same inputs.
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
insert_batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -328,11 +344,12 @@ pub fn delete_1m_2k_rand(c: &mut Criterion) {
.expect("apply failed");

b.iter_with_large_drop(|| {
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
delete_batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -361,11 +378,12 @@ pub fn prove_1m_2k_rand(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -378,7 +396,7 @@ pub fn prove_1m_2k_rand(c: &mut Criterion) {
.expect("apply failed");
let mut prove_keys = Vec::with_capacity(batch_size);
for (key, _) in batch.iter() {
prove_keys.push(merk::proofs::query::query_item::QueryItem::Key(key.clone()));
prove_keys.push(proofs::query::query_item::QueryItem::Key(key.clone()));
}
prove_keys_per_batch.push(prove_keys);
batches.push(batch);
Expand Down Expand Up @@ -409,11 +427,12 @@ pub fn build_trunk_chunk_1m_2k_rand(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -434,7 +453,7 @@ pub fn build_trunk_chunk_1m_2k_rand(c: &mut Criterion) {

let (ops, _) =
merk.walk(|walker| walker.unwrap().create_trunk_proof().unwrap().unwrap());
encode_proof_into(ops.iter(), &mut bytes);
proofs::encode_into(ops.iter(), &mut bytes);
});
});
}
Expand All @@ -450,11 +469,12 @@ pub fn chunkproducer_rand_1m_1_rand(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -489,11 +509,12 @@ pub fn chunk_iter_1m_1(c: &mut Criterion) {

for i in 0..n_batches {
let batch = make_batch_rand(batch_size as u64, i as u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand Down Expand Up @@ -530,11 +551,12 @@ pub fn restore_500_1(c: &mut Criterion) {
let mut merk = TempMerk::new();

let batch = make_batch_rand(merk_size as u64, 0_u64);
merk.apply_unchecked::<_, Vec<u8>, _, _, _>(
merk.apply_unchecked::<_, Vec<u8>, _, _, _, _>(
&batch,
&[],
None,
&|_k, _v| Ok(0),
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
&mut |_costs, _old_value, _value| Ok((false, None)),
&mut |_a, key_bytes_to_remove, value_bytes_to_remove| {
Ok((
Expand All @@ -560,7 +582,13 @@ pub fn restore_500_1(c: &mut Criterion) {
.0
.get_immediate_storage_context(SubtreePath::empty(), &tx)
.unwrap();
let m = Merk::open_standalone(ctx, false).unwrap().unwrap();
let m = Merk::open_standalone(
ctx,
false,
None::<&fn(&[u8]) -> Option<ValueDefinedCostType>>,
)
.unwrap()
.unwrap();
let mut restorer = Merk::restore(m, root_hash);

for chunk in data.1 {
Expand Down
7 changes: 6 additions & 1 deletion merk/benches/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
//! Merk benches ops

use criterion::{criterion_group, criterion_main, Criterion};
use merk::{owner::Owner, test_utils::*};
use grovedb_merk::{
owner::Owner,
test_utils::{
apply_memonly_unchecked, make_batch_rand, make_batch_seq, make_tree_rand, make_tree_seq,
},
};

/// 1m sequential inserts in 10k batches, memonly
fn insert_1m_10k_seq_memonly(c: &mut Criterion) {
Expand Down
2 changes: 0 additions & 2 deletions merk/src/merk/committer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use grovedb_costs::storage_cost::key_value_cost::KeyValueStorageCost;

use crate::{
merk::BatchValue,
tree::{Commit, TreeNode},
Expand Down
11 changes: 4 additions & 7 deletions merk/src/merk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,18 @@ use std::{
use committer::MerkCommitter;
use grovedb_costs::{
cost_return_on_error, cost_return_on_error_default, cost_return_on_error_no_add,
storage_cost::{
key_value_cost::KeyValueStorageCost, removal::StorageRemovedBytes, StorageCost,
},
ChildrenSizesWithValue, CostContext, CostResult, CostsExt, FeatureSumLength, OperationCost,
storage_cost::key_value_cost::KeyValueStorageCost, ChildrenSizesWithValue, CostContext,
CostResult, CostsExt, FeatureSumLength, OperationCost,
};
use grovedb_storage::{self, Batch, RawIterator, StorageContext};
use source::MerkSource;

use crate::{
error::Error,
merk::{defaults::ROOT_KEY_KEY, options::MerkOptions},
proofs::{query::query_item::QueryItem, Op as ProofOp, Query},
proofs::{query::query_item::QueryItem, Query},
tree::{
kv::ValueDefinedCostType, AuxMerkBatch, Commit, CryptoHash, Fetch, Op, RefWalker, TreeNode,
NULL_HASH,
kv::ValueDefinedCostType, AuxMerkBatch, CryptoHash, Op, RefWalker, TreeNode, NULL_HASH,
},
Error::{CostsError, EdError, StorageError},
MerkType::{BaseMerk, LayeredMerk, StandaloneMerk},
Expand Down
1 change: 0 additions & 1 deletion merk/src/proofs/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ pub(crate) fn verify_trunk<I: Iterator<Item = Result<Op, Error>>>(
mod tests {
use std::usize;

use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval;
use grovedb_storage::StorageContext;

use super::{super::tree::Tree, *};
Expand Down
1 change: 0 additions & 1 deletion merk/src/proofs/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ where
#[allow(deprecated)]
#[cfg(test)]
mod test {
use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval;

use super::{
super::{encoding::encode_into, *},
Expand Down
4 changes: 0 additions & 4 deletions merk/src/tree/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@

//! Merk tree commit

#[cfg(feature = "full")]
use grovedb_costs::storage_cost::{removal::StorageRemovedBytes, StorageCost};

#[cfg(feature = "full")]
use super::TreeNode;
#[cfg(feature = "full")]
use crate::error::Error;
use crate::tree::kv::ValueDefinedCostType;

#[cfg(feature = "full")]
/// To be used when committing a tree (writing it to a store after applying the
Expand Down
1 change: 0 additions & 1 deletion merk/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@ pub const fn side_to_str(left: bool) -> &'static str {
#[cfg(feature = "full")]
#[cfg(test)]
mod test {
use grovedb_costs::storage_cost::removal::StorageRemovedBytes::NoStorageRemoval;

use super::{commit::NoopCommit, hash::NULL_HASH, TreeNode};
use crate::tree::{
Expand Down
Loading

0 comments on commit 6bef9c9

Please sign in to comment.