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

optimize get_proof_positions to not use sort #66

Merged

Conversation

Davidson-Souza
Copy link
Collaborator

Calling sort on every iteration for a method that's called at least once every block is a huge perf hit. This commit rework get_proof_positions to work without sorting.

The reason why we sort is that we always work upwards in the tree, starting at row 0 and going all the way to the top-most root. We always need a node and it's sibling (either from the proof or computed as we go). Searching for a sibling is also incredibly slow, given that we might have up to hundreds of thousands of nodes. We want to have siblings adjacent to each other inside our container. If all leaves were at row 0, that would always happen. But since leaves may not be at row 0, it is possible to have siblings being scattered around. To fix this, we might just sort the vector, siblings are numerically adjacent. However, sorting a few thousand nodes is also expensive.

This commit uses a BTreeMap instead of a vector. We trade-off some small performance on searching, but now we can add stuff in a self-sorting way that's much lighter.

Calling sort on every iteration for a method that's called at least once
every block is a huge perf hit. This commit rework `get_proof_positions`
to work without sorting.

The reason why we sort is that we always work upwards in the tree,
starting at row 0 and going all the way to the top-most root. We always
need a node and it's sibling (either from the proof or computed as we
go). Searching for a sibling is also incredibly slow, given that we
might have up to hundreds of thousands of nodes. We want to have
siblings adjacent to each other inside our container. If all leaves were
at row 0, that would always happen. But since leaves may not be at row
0, it is possible to have siblings being scattered around. To fix this,
we might just sort the vector, siblings are numerically adjacent.
However, sorting a few thousand nodes is also expensive.

This commit uses a BTreeMap instead of a vector. We trade-off some small
performance on searching, but now we can add stuff in a self-sorting way
that's much lighter.
@Davidson-Souza Davidson-Souza force-pushed the proof-position-sortless branch from 395519e to 13567e7 Compare February 5, 2025 14:10
@Davidson-Souza Davidson-Souza merged commit 2466fd0 into mit-dci:main Feb 5, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant