Skip to content

Commit

Permalink
perf(crypto): apply powersort to `FieldMerkleTreeMMCS::DoVerifyOpen…
Browse files Browse the repository at this point in the history
…ingProof()`
  • Loading branch information
chokobole committed Aug 7, 2024
1 parent d6c5f20 commit e46908e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tachyon_cc_library(
deps = [
":field_merkle_tree",
"//tachyon/base:bits",
"//tachyon/base:sort",
"//tachyon/crypto/commitments:mixed_matrix_commitment_scheme",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class FieldMerkleTreeMMCS final
size_t index;
math::Dimensions dimensions;

// TODO(chokobole): This comparison is intentionally reversed to sort in
// descending order, as powersort doesn't accept custom callbacks.
bool operator<(const IndexedDimensions& other) const {
return dimensions.height > other.dimensions.height;
}
bool operator<=(const IndexedDimensions& other) const {
return dimensions.height >= other.dimensions.height;
}
bool operator>(const IndexedDimensions& other) const {
return dimensions.height < other.dimensions.height;
}

std::string ToString() const {
return absl::Substitute("($0, $1)", index, dimensions.ToString());
}
Expand Down Expand Up @@ -131,13 +143,8 @@ class FieldMerkleTreeMMCS final
return IndexedDimensions{index, dimensions};
});

// TODO(chokobole): Use https://github.com/timsort/cpp-TimSort or
// https://github.com/sebawild/powersort for better performance.
std::stable_sort(
sorted_dimensions_list.begin(), sorted_dimensions_list.end(),
[](const IndexedDimensions& a, const IndexedDimensions& b) {
return a.dimensions.height > b.dimensions.height;
});
base::StableSort(sorted_dimensions_list.begin(),
sorted_dimensions_list.end());

absl::Span<const IndexedDimensions> remaining_dimensions_list =
absl::MakeConstSpan(sorted_dimensions_list);
Expand Down

0 comments on commit e46908e

Please sign in to comment.