-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
perf: speedup of CBLSLazyPublicKey::operator== when comparing to the default / null object; speedup CDeterministicMNList::AddMN by avoiding check to IsValid when a nullcheck is sufficient #6581
base: develop
Are you sure you want to change the base?
perf: speedup of CBLSLazyPublicKey::operator== when comparing to the default / null object; speedup CDeterministicMNList::AddMN by avoiding check to IsValid when a nullcheck is sufficient #6581
Conversation
WalkthroughThis pull request introduces changes in three main areas. In the BLS module, the ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Reindex finished successfully |
…default / null object; speedup CDeterministicMNList::AddMN by avoiding check to IsValid when a nullcheck is sufficient
40909d7
to
ada6f2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ada6f2b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/test/bls_tests.cpp (2)
475-524
: Enhance class documentation and exception safety.Consider the following improvements to the
DummyBLS
class:
- Add method documentation explaining the purpose and contract of each public method
- Add
noexcept
specifications where applicable (e.g., constructors, Reset, IsValid)- Mark methods that don't modify state as
const
class DummyBLS { public: static const size_t SerSize = 4; std::array<uint8_t, SerSize> data{}; - DummyBLS() { + /// Default constructor initializing data to zeros + DummyBLS() noexcept { data.fill(0); } + /// @returns true if any byte in data is non-zero bool IsValid() const { return std::any_of(data.begin(), data.end(), [](uint8_t c){ return c != 0; }); } + /// @returns data array ignoring legacy flag std::array<uint8_t, SerSize> ToBytes(bool /*legacy*/) const { return data; } + /// Sets data from bytes array ignoring legacy flag void SetBytes(const std::array<uint8_t, SerSize>& bytes, bool /*legacy*/) { data = bytes; } + /// @returns true if data matches given bytes ignoring legacy flag bool CheckMalleable(const std::array<uint8_t, SerSize>& bytes, bool /*legacy*/) const { return data == bytes; } + /// Resets data to zeros void Reset() noexcept { data.fill(0); }
529-609
: Add test coverage for edge cases and error conditions.While the current test suite is good, consider adding the following test cases:
- Test behavior with invalid data
- Test error conditions in serialization/deserialization
- Test the Reset() functionality
- Test behavior with zero-filled but non-default objects
Would you like me to generate the additional test cases?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/bls/bls.h
(3 hunks)src/evo/deterministicmns.cpp
(3 hunks)src/test/bls_tests.cpp
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/bls/bls.h
- src/evo/deterministicmns.cpp
🧰 Additional context used
🪛 GitHub Actions: Clang Diff Format Check
src/test/bls_tests.cpp
[error] 473-473: Clang format differences found. Please run 'clang-format' to format the code.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build container / Build container
🔇 Additional comments (1)
src/test/bls_tests.cpp (1)
526-527
: LGTM!The type alias is well-defined and appropriately named.
@@ -472,4 +472,140 @@ BOOST_AUTO_TEST_CASE(bls_threshold_signature_tests) | |||
FuncThresholdSignature(false); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix clang-format issue.
The CI pipeline indicates a formatting issue. Please run clang-format on the file to resolve this.
🧰 Tools
🪛 GitHub Actions: Clang Diff Format Check
[error] 473-473: Clang format differences found. Please run 'clang-format' to format the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK e18f621
src/test/bls_tests.cpp
Outdated
DummyBLS obj; | ||
obj.data = {1, 2, 3, 4}; // nonzero data makes the object valid | ||
lazy_a.Set(obj, false); | ||
obj.data = {4, 3, 2, 1}; // nonzero data makes the object valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe make only 1 byte difference here, to catch error "any_of" vs "all_of" in operator ==
obj.data = {0, 2, 3, 4}; // nonzero data makes the object valid
LazyDummyBLS lazy2; | ||
BOOST_CHECK(lazy1 == lazy2); | ||
DummyBLS obj; | ||
obj.data = {5, 6, 7, 8}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe make only 1 byte difference here, to catch error "any_of" vs "all_of".
such as:
obj.data = {1, 2, 3, 5};
src/test/bls_tests.cpp
Outdated
|
||
// Produce a string representation. | ||
std::string ToString(bool /*legacy*/) const { | ||
std::ostringstream oss; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: refactor by using HexStr
from src/util/strencodings.h
Looks good but clang-format complains a lot. Pls consider formatting new tests accordingly (and also pls add a new line at eof). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/test/bls_tests.cpp (2)
475-515
: LGTM! Clean and efficient implementation of the DummyBLS class.The class provides a good minimal interface for testing CBLSLazyWrapper with efficient implementations. The use of std::array and std::any_of shows good C++ practices.
Consider simplifying the ToString method using HexStr from src/util/strencodings.h as suggested in the past review:
- std::string ToString(bool /*legacy*/) const - { - std::ostringstream oss; - for (auto b : data) { - oss << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(b); - } - return oss.str(); - } + std::string ToString(bool /*legacy*/) const + { + return HexStr(data); + }
520-600
: LGTM! Comprehensive test coverage for LazyDummyBLS.The test suite thoroughly covers equality comparisons, serialization, and hash consistency.
Consider modifying the test data to better catch potential edge cases. As suggested in past reviews, use minimal differences:
- obj.data = {1, 2, 3, 4}; // nonzero data makes the object valid + obj.data = {1, 0, 0, 0}; // single nonzero byte to catch any_of vs all_of errorsThis change would help catch potential issues with the IsValid() implementation if it were mistakenly using all_of instead of any_of.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/evo/deterministicmns.cpp
(3 hunks)src/test/bls_tests.cpp
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/evo/deterministicmns.cpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build container / Build container
🔇 Additional comments (2)
src/test/bls_tests.cpp (2)
517-518
: LGTM! Clear type alias definition.The type alias improves readability in the test cases.
473-473
: Fix clang-format issue.The CI pipeline indicates a formatting issue. Please run clang-format on the file to resolve this.
pls consider fe5250a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/test/bls_tests.cpp (5)
489-489
: Consider using std::ranges::any_of for modern C++.For better readability and maintainability, consider using the more modern std::ranges::any_of algorithm.
- return std::any_of(data.begin(), data.end(), [](uint8_t c) { return c != 0; }); + return std::ranges::any_of(data, [](uint8_t c) { return c != 0; });
529-529
: Consider using more diverse test data.The test data could be more diverse to catch edge cases. For example:
- Test with all zeros except the last byte
- Test with alternating patterns
- Test with all maximum values (0xFF)
- obj.data = {1, 0, 0, 0}; // nonzero data makes the object valid + obj.data = {0, 0, 0, 1}; // Test last byte non-zero- obj.data = {1, 2, 3, 4}; // nonzero data makes the object valid + obj.data = {0xAA, 0x55, 0xAA, 0x55}; // Test alternating pattern- obj.data = {5, 6, 7, 8}; + obj.data = {0xFF, 0xFF, 0xFF, 0xFF}; // Test maximum valuesAlso applies to: 541-541, 555-555
535-535
: Fix duplicate test case comment.The comment for this test case is identical to the previous one (Test 2), but the test case is different.
-// Test 2: A default wrapper and one initialized with a nonzero DummyBLS should compare unequal. +// Test 3: Two different non-default wrappers should compare unequal.
572-573
: Consider testing different serialization versions.The serialization tests only verify with a single legacy flag value. Consider testing both legacy and non-legacy serialization.
CDataStream ds(SER_DISK, CLIENT_VERSION); - lazy1.Serialize(ds, true); + // Test both legacy and non-legacy serialization + lazy1.Serialize(ds, true); + lazy1.Serialize(ds, false); LazyDummyBLS lazy2; - lazy2.Unserialize(ds, true); - BOOST_CHECK(lazy1 == lazy2); + lazy2.Unserialize(ds, true); + BOOST_CHECK(lazy1 == lazy2); + lazy2.Unserialize(ds, false); + BOOST_CHECK(lazy1 == lazy2);Also applies to: 577-578
582-594
: Consider adding hash collision test.The hash consistency test is good, but consider adding a test to verify that different objects produce different hashes.
uint256 hash1 = lazy1.GetHash(); uint256 hash2 = lazy2.GetHash(); BOOST_CHECK(hash1 == hash2); + + // Test that different objects have different hashes + DummyBLS different_obj; + different_obj.data = {16, 15, 14, 13}; // Different from original + lazy2.Set(different_obj, false); + uint256 hash3 = lazy2.GetHash(); + BOOST_CHECK(hash1 != hash3);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/test/bls_tests.cpp
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build container / Build container
🔇 Additional comments (2)
src/test/bls_tests.cpp (2)
476-509
: LGTM! Well-structured mock implementation.The DummyBLS class provides a clean and minimal interface required by CBLSLazyWrapper. The implementation includes all necessary methods with clear documentation.
505-505
: Good use of HexStr utility.Excellent use of the HexStr utility from strencodings.h for string representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, utACK 0cf8a46
Profiling Analysis
before

after

Methods
Below, is some analysis on the results of running the
protx diff
RPC 500 times. The diffs had a start block between MIN and MAX as defined below; and an end block no more than MAX_DIFF from the selected start block. We then perform some statistical analysis on the data.MIN_VALUE = 1500050
MAX_VALUE = 2000050
MAX_DIFF = 50000

Statistical Analysis, outliers included
Before
Five-Number Summary of Execution Times:
Min: 0.024492 sec
Q1: 0.124626 sec
Median: 0.243000 sec
Q3: 0.358459 sec
Max: 15.583948 sec
Mean Execution Time: 0.428296 sec
Standard Deviation: 0.933486 sec
Linear Regression Results:


y = 0.000001 * x + 0.308662
R-squared: 0.008160 (Goodness of Fit)
After
Five-Number Summary of Execution Times:
Min: 0.038174 sec
Q1: 0.121363 sec
Median: 0.158175 sec
Q3: 0.215866 sec
Max: 16.587903 sec
Mean Execution Time: 0.239239 sec
Standard Deviation: 0.762387 sec
Linear Regression Results:


y = 0.000001 * x + 0.151169
R-squared: 0.006918 (Goodness of Fit)
P-value: 0.063105 (Significance)
Statistical Analysis, outliers excluded
Before
removed 76 data points
Five-Number Summary of Execution Times (After Outlier Removal):
Min: 0.035916 sec
Q1: 0.211060 sec
Median: 0.319278 sec
Q3: 0.357963 sec
Max: 0.572785 sec
Mean Execution Time: 0.289764 sec
Standard Deviation: 0.101140 sec
Linear Regression Results (After Outlier Removal):

y = 0.0000000199 * x + 0.286447
R-squared: 0.000496 (Goodness of Fit)
After
removed 32 data points
Five-Number Summary of Execution Times (After Outlier Removal):
Min: 0.038174 sec
Q1: 0.119880 sec
Median: 0.151724 sec
Q3: 0.205017 sec
Max: 0.355078 sec
Mean Execution Time: 0.164165 sec
Standard Deviation: 0.060919 sec
Linear Regression Results (After Outlier Removal):
y = 0.0000003119 * x + 0.111002
R-squared: 0.399298 (Goodness of Fit)
How Has This Been Tested?
Ran unit tests locally; reindexing currently, going to let CI run functional tests
Breaking Changes
Should be none; but please think through the diff specifically related to https://github.com/dashpay/dash/compare/develop...PastaPastaPasta:dash:perf-build-simplified-mn-list-diff-bls-compare-to-null?expand=1#diff-0998f8dfc4c1089e90cbaafe9607b361035b904cd103df31e3c2339a3cbf790dR480
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.