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

feat: Sequential insertion in indexed trees #10111

Merged
merged 42 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0801f37
add sequential insertion
sirasistant Nov 21, 2024
18c052e
fixes
sirasistant Nov 21, 2024
66ba930
refactor
sirasistant Nov 21, 2024
a3f2c0c
fix capture
sirasistant Nov 21, 2024
ac6498f
fix
sirasistant Nov 22, 2024
bc5ec50
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 22, 2024
e9d4d43
fmt
sirasistant Nov 22, 2024
c10abc3
fix some units
sirasistant Nov 22, 2024
a526cbe
Merge branch 'arv/insert_sequential' of github.com:AztecProtocol/azte…
sirasistant Nov 22, 2024
35b22b5
refactor rename
sirasistant Nov 22, 2024
debdc60
fix
sirasistant Nov 22, 2024
014fb45
fix
sirasistant Nov 22, 2024
906141b
fix
sirasistant Nov 22, 2024
a7ff1c3
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 25, 2024
2ea6fdf
document caching issue
sirasistant Nov 25, 2024
d0040d4
test and bench
sirasistant Nov 25, 2024
507d14d
reorder bench
sirasistant Nov 25, 2024
649d52d
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 25, 2024
34f10ef
docs
sirasistant Nov 25, 2024
25c5bc5
remove batches in sync
sirasistant Nov 25, 2024
fca466e
fix type
sirasistant Nov 25, 2024
d50f8f1
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 25, 2024
716755f
add specific test for multiple updates to the same leaf in the same call
sirasistant Nov 25, 2024
df603fe
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
1b6462b
fix: empty leaf hashing
sirasistant Nov 26, 2024
d7191f8
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
df773ad
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
413227f
fix corner case
sirasistant Nov 26, 2024
e4fa6a5
Merge branch 'arv/insert_sequential' of github.com:AztecProtocol/azte…
sirasistant Nov 26, 2024
b1b8552
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
66f64b1
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
c12ab24
fix
sirasistant Nov 26, 2024
ce6297d
restore publicDataWritesCount
sirasistant Nov 26, 2024
fa2291e
Merge branch 'arv/insert_sequential' of github.com:AztecProtocol/azte…
sirasistant Nov 26, 2024
f4586ca
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
9d43a28
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 26, 2024
5adde1e
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 27, 2024
98ae886
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 27, 2024
1b74135
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 28, 2024
d544e4c
use explicit fr::zero
sirasistant Nov 28, 2024
92823b4
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 28, 2024
d6324d6
Merge branch 'master' into arv/insert_sequential
sirasistant Nov 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,79 @@ const size_t MAX_BATCH_SIZE = 64;
template <typename TreeType> void add_values(TreeType& tree, const std::vector<NullifierLeafValue>& values)
{
Signal signal(1);
typename TreeType::AddCompletionCallback completion = [&](const auto&) -> void { signal.signal_level(0); };
bool success = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the sequential insertion compare with the batch insertion?

The mutli-threaded batch insertion doesn't perform as well as I had hoped. It was much better when we used pedersen as a much greater portion of the time was spent hashing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With witnesses, it's worse (that's expected since you're fetching more witnesses)
However, without witnesses, it's better single threaded (yay) but worse multithreaded. That one is a weird one, since I expected sparse_batch_update (which is the only thing sequential insertion without witnesses does) to perform better than sparse_batch_update and then append. Do you know why this could be the case? Should I profile this thing?
Here is the bench results I got on mainframe (not the best place for benching but good enough I hope)

single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/2/iterations:1000             1.84 ms        0.028 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/4/iterations:1000             2.99 ms        0.031 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/8/iterations:1000             5.48 ms        0.029 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/16/iterations:1000            10.2 ms        0.027 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/32/iterations:1000            20.2 ms        0.034 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/64/iterations:1000            39.4 ms        0.041 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/512/iterations:10              303 ms        0.081 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/1024/iterations:10             647 ms        0.093 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/2048/iterations:10            1271 ms        0.125 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/4096/iterations:10            2471 ms        0.237 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/8192/iterations:10            4966 ms        0.388 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/2/iterations:1000        2.22 ms        0.018 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/4/iterations:1000        4.92 ms        0.029 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/8/iterations:1000        9.24 ms        0.029 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/16/iterations:1000       18.2 ms        0.028 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/32/iterations:1000       36.2 ms        0.033 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/64/iterations:1000       73.7 ms        0.044 ms         1000
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/512/iterations:10         575 ms        0.076 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/1024/iterations:10       1187 ms        0.091 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/2048/iterations:10       2406 ms        0.106 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/4096/iterations:10       5038 ms        0.148 ms           10
single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/8192/iterations:10      11375 ms        0.942 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/2/iterations:1000              1.75 ms        0.022 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/4/iterations:1000              1.69 ms        0.027 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/8/iterations:1000              2.32 ms        0.023 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/16/iterations:1000             4.16 ms        0.033 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/32/iterations:1000             6.99 ms        0.029 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/64/iterations:1000             13.8 ms        0.030 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/512/iterations:10              82.9 ms        0.057 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/1024/iterations:10              143 ms        0.083 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/2048/iterations:10              341 ms        0.115 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/4096/iterations:10              663 ms        0.174 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>/8192/iterations:10             1489 ms        0.226 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/2/iterations:1000         1.03 ms        0.020 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/4/iterations:1000         1.43 ms        0.019 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/8/iterations:1000         2.74 ms        0.020 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/16/iterations:1000        4.95 ms        0.022 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/32/iterations:1000        10.0 ms        0.025 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/64/iterations:1000        20.6 ms        0.024 ms         1000
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/512/iterations:10          126 ms        0.053 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/1024/iterations:10         279 ms        0.072 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/2048/iterations:10         658 ms        0.104 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/4096/iterations:10        1641 ms        0.213 ms           10
multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>/8192/iterations:10        4417 ms        0.286 ms           10
single_thread_indexed_tree_bench<Poseidon2, BATCH>/2/iterations:1000                          1.32 ms        0.019 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/4/iterations:1000                          1.80 ms        0.023 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/8/iterations:1000                          2.54 ms        0.025 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/16/iterations:1000                         4.04 ms        0.025 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/32/iterations:1000                         7.11 ms        0.028 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/64/iterations:1000                         13.4 ms        0.037 ms         1000
single_thread_indexed_tree_bench<Poseidon2, BATCH>/512/iterations:10                          64.9 ms        0.077 ms           10
single_thread_indexed_tree_bench<Poseidon2, BATCH>/1024/iterations:10                          120 ms        0.099 ms           10
single_thread_indexed_tree_bench<Poseidon2, BATCH>/2048/iterations:10                          211 ms        0.089 ms           10
single_thread_indexed_tree_bench<Poseidon2, BATCH>/4096/iterations:10                          389 ms        0.159 ms           10
single_thread_indexed_tree_bench<Poseidon2, BATCH>/8192/iterations:10                          777 ms        0.696 ms           10
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/2/iterations:1000                     1.01 ms        0.018 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/4/iterations:1000                     1.47 ms        0.019 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/8/iterations:1000                     2.20 ms        0.024 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/16/iterations:1000                    3.84 ms        0.023 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/32/iterations:1000                    6.64 ms        0.030 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/64/iterations:1000                    12.5 ms        0.032 ms         1000
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/512/iterations:10                     63.7 ms        0.074 ms           10
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/1024/iterations:10                     112 ms        0.079 ms           10
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/2048/iterations:10                     205 ms        0.108 ms           10
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/4096/iterations:10                     374 ms        0.152 ms           10
single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/8192/iterations:10                     730 ms        0.402 ms           10
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/2/iterations:1000                           1.43 ms        0.026 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/4/iterations:1000                           1.68 ms        0.033 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/8/iterations:1000                           1.98 ms        0.028 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/16/iterations:1000                          2.55 ms        0.029 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/32/iterations:1000                          3.75 ms        0.034 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/64/iterations:1000                          6.05 ms        0.034 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/512/iterations:100                          31.7 ms        0.060 ms          100
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/1024/iterations:100                         71.2 ms        0.095 ms          100
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/2048/iterations:100                          124 ms        0.106 ms          100
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/4096/iterations:100                          248 ms        0.153 ms          100
multi_thread_indexed_tree_bench<Poseidon2, BATCH>/8192/iterations:100                          594 ms        0.245 ms          100
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/2/iterations:1000                     0.859 ms        0.020 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/4/iterations:1000                     0.987 ms        0.022 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/8/iterations:1000                      1.30 ms        0.024 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/16/iterations:1000                     2.46 ms        0.034 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/32/iterations:1000                     3.68 ms        0.040 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/64/iterations:1000                     5.84 ms        0.031 ms         1000
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/512/iterations:100                     40.1 ms        0.069 ms          100
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/1024/iterations:100                    62.7 ms        0.086 ms          100
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/2048/iterations:100                     139 ms        0.115 ms          100
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/4096/iterations:100                     246 ms        0.153 ms          100
multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>/8192/iterations:100                     808 ms        0.301 ms          100

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed. Looks like the multi-threaded performs a little better in most scenarios. I think we should wait until the compete use case of the world state has settled further and then optimise.

std::string error_message;
typename TreeType::AddCompletionCallback completion = [&](const auto& result) -> void {
success = result.success;
error_message = result.message;
signal.signal_level(0);
};

tree.add_or_update_values(values, completion);
signal.wait_for_level(0);
if (!success) {
throw std::runtime_error(format("Failed to add values: ", error_message));
}
}

template <typename TreeType> void add_values_with_witness(TreeType& tree, const std::vector<NullifierLeafValue>& values)
{
bool success = true;
std::string error_message;
Signal signal(1);
typename TreeType::AddCompletionCallbackWithWitness completion = [&](const auto&) -> void {
typename TreeType::AddCompletionCallbackWithWitness completion = [&](const auto& result) -> void {
success = result.success;
error_message = result.message;
signal.signal_level(0);
};

tree.add_or_update_values(values, completion);
signal.wait_for_level(0);
if (!success) {
throw std::runtime_error(format("Failed to add values with witness: ", error_message));
}
}

template <typename TreeType> void add_values_sequentially(TreeType& tree, const std::vector<NullifierLeafValue>& values)
{
bool success = true;
std::string error_message;
Signal signal(1);
typename TreeType::AddCompletionCallback completion = [&](const auto& result) -> void {
success = result.success;
error_message = result.message;
signal.signal_level(0);
};

tree.add_or_update_values_sequentially(values, completion);
signal.wait_for_level(0);
if (!success) {
throw std::runtime_error(format("Failed to add values sequentially: ", error_message));
}
}

template <typename TreeType>
void add_values_sequentially_with_witness(TreeType& tree, const std::vector<NullifierLeafValue>& values)
{
bool success = true;
std::string error_message;
Signal signal(1);
typename TreeType::AddSequentiallyCompletionCallbackWithWitness completion = [&](const auto& result) -> void {
success = result.success;
error_message = result.message;
signal.signal_level(0);
};

tree.add_or_update_values_sequentially(values, completion);
signal.wait_for_level(0);
if (!success) {
throw std::runtime_error(format("Failed to add values sequentially with witness: ", error_message));
}
}

template <typename TreeType> void multi_thread_indexed_tree_bench(State& state) noexcept
enum InsertionStrategy { SEQUENTIAL, BATCH };

template <typename TreeType, InsertionStrategy strategy> void multi_thread_indexed_tree_bench(State& state) noexcept
{
const size_t batch_size = size_t(state.range(0));
const size_t depth = TREE_DEPTH;
Expand All @@ -61,10 +116,14 @@ template <typename TreeType> void multi_thread_indexed_tree_bench(State& state)

const size_t initial_size = 1024 * 16;
std::vector<NullifierLeafValue> initial_batch(initial_size);
for (size_t i = 0; i < batch_size; ++i) {
for (size_t i = 0; i < initial_size; ++i) {
initial_batch[i] = fr(random_engine.get_random_uint256());
}
add_values(tree, initial_batch);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, initial_batch);
} else {
add_values(tree, initial_batch);
}

for (auto _ : state) {
state.PauseTiming();
Expand All @@ -73,11 +132,15 @@ template <typename TreeType> void multi_thread_indexed_tree_bench(State& state)
values[i] = fr(random_engine.get_random_uint256());
}
state.ResumeTiming();
add_values(tree, values);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, values);
} else {
add_values(tree, values);
}
}
}

template <typename TreeType> void single_thread_indexed_tree_bench(State& state) noexcept
template <typename TreeType, InsertionStrategy strategy> void single_thread_indexed_tree_bench(State& state) noexcept
{
const size_t batch_size = size_t(state.range(0));
const size_t depth = TREE_DEPTH;
Expand All @@ -94,10 +157,14 @@ template <typename TreeType> void single_thread_indexed_tree_bench(State& state)

const size_t initial_size = 1024 * 16;
std::vector<NullifierLeafValue> initial_batch(initial_size);
for (size_t i = 0; i < batch_size; ++i) {
for (size_t i = 0; i < initial_size; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That look like a bug, nice catch

initial_batch[i] = fr(random_engine.get_random_uint256());
}
add_values(tree, initial_batch);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, initial_batch);
} else {
add_values(tree, initial_batch);
}

for (auto _ : state) {
state.PauseTiming();
Expand All @@ -106,11 +173,16 @@ template <typename TreeType> void single_thread_indexed_tree_bench(State& state)
values[i] = fr(random_engine.get_random_uint256());
}
state.ResumeTiming();
add_values(tree, values);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, values);
} else {
add_values(tree, values);
}
}
}

template <typename TreeType> void multi_thread_indexed_tree_with_witness_bench(State& state) noexcept
template <typename TreeType, InsertionStrategy strategy>
void multi_thread_indexed_tree_with_witness_bench(State& state) noexcept
{
const size_t batch_size = size_t(state.range(0));
const size_t depth = TREE_DEPTH;
Expand All @@ -127,10 +199,14 @@ template <typename TreeType> void multi_thread_indexed_tree_with_witness_bench(S

const size_t initial_size = 1024 * 16;
std::vector<NullifierLeafValue> initial_batch(initial_size);
for (size_t i = 0; i < batch_size; ++i) {
for (size_t i = 0; i < initial_size; ++i) {
initial_batch[i] = fr(random_engine.get_random_uint256());
}
add_values(tree, initial_batch);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, initial_batch);
} else {
add_values(tree, initial_batch);
}

for (auto _ : state) {
state.PauseTiming();
Expand All @@ -139,11 +215,16 @@ template <typename TreeType> void multi_thread_indexed_tree_with_witness_bench(S
values[i] = fr(random_engine.get_random_uint256());
}
state.ResumeTiming();
add_values_with_witness(tree, values);
if (strategy == SEQUENTIAL) {
add_values_sequentially_with_witness(tree, values);
} else {
add_values_with_witness(tree, values);
}
}
}

template <typename TreeType> void single_thread_indexed_tree_with_witness_bench(State& state) noexcept
template <typename TreeType, InsertionStrategy strategy>
void single_thread_indexed_tree_with_witness_bench(State& state) noexcept
{
const size_t batch_size = size_t(state.range(0));
const size_t depth = TREE_DEPTH;
Expand All @@ -160,10 +241,14 @@ template <typename TreeType> void single_thread_indexed_tree_with_witness_bench(

const size_t initial_size = 1024 * 16;
std::vector<NullifierLeafValue> initial_batch(initial_size);
for (size_t i = 0; i < batch_size; ++i) {
for (size_t i = 0; i < initial_size; ++i) {
initial_batch[i] = fr(random_engine.get_random_uint256());
}
add_values(tree, initial_batch);
if (strategy == SEQUENTIAL) {
add_values_sequentially(tree, initial_batch);
} else {
add_values(tree, initial_batch);
}

for (auto _ : state) {
state.PauseTiming();
Expand All @@ -172,53 +257,105 @@ template <typename TreeType> void single_thread_indexed_tree_with_witness_bench(
values[i] = fr(random_engine.get_random_uint256());
}
state.ResumeTiming();
add_values_with_witness(tree, values);
if (strategy == SEQUENTIAL) {
add_values_sequentially_with_witness(tree, values);
} else {
add_values_with_witness(tree, values);
}
}
}

BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2>)
BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2>)
BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2>)
BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2>)
BENCHMARK(single_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2>)
BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2>)
BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2>)
BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(multi_thread_indexed_tree_with_witness_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(single_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(10);

BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, BATCH>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
->Iterations(100);

BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(2, MAX_BATCH_SIZE)
->Iterations(1000);

BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2>)
BENCHMARK(multi_thread_indexed_tree_bench<Poseidon2, SEQUENTIAL>)
->Unit(benchmark::kMillisecond)
->RangeMultiplier(2)
->Range(512, 8192)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,16 @@ std::optional<fr> ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_lea

if (!child.has_value()) {
// std::cout << "No child" << std::endl;
// We still need to update the cache with the sibling. The fact that under us there is an empty subtree
// doesn't mean that same is happening with our sibling.
if (updateNodesByIndexCache) {
child_index_at_level = is_right ? (child_index_at_level * 2) + 1 : (child_index_at_level * 2);
std::optional<fr> sibling = is_right ? nodePayload.left : nodePayload.right;
index_t sibling_index_at_level = is_right ? child_index_at_level - 1 : child_index_at_level + 1;
if (sibling.has_value()) {
store_->put_cached_node_by_index(i + 1, sibling_index_at_level, sibling.value(), false);
}
}
return std::nullopt;
}
// std::cout << "Found child " << child.value() << std::endl;
Expand Down
Loading
Loading