Bug Description
public_key_type has no operator< implementation, but it can be implicitly converted to address (at the cost of a SHA512 calculation) which does. Thus any set or map keyed on public_key_type does two SHA512 calculations per operator< call. This is ridiculously slow.
Impacts
Describe which portion(s) of Peerplays may be impacted by this bug. Please tick at least one box.
Additional Context (optional)
Benching code:
BOOST_AUTO_TEST_CASE(public_key_type_comparison) {
flat_set<public_key_type> s1;
for (int i = 0; i < 5; ++i)
s1.insert(fc::ecc::private_key::generate().get_public_key());
flat_set<public_key_type, pubkey_comparator> s2(s1.begin(), s1.end());
const int rounds = 1'000'000;
auto start = fc::time_point::now();
for (int i = 0; i < rounds; ++i)
BOOST_CHECK(s1.contains(*s1.begin()));
auto end = fc::time_point::now();
wlog("public_key_type default comparion: ${rounds} rounds in ${ms} ms",
("rounds", rounds)("ms", (end-start).count()/1000));
start = fc::time_point::now();
for (int i = 0; i < rounds; ++i)
BOOST_CHECK(s2.contains(*s2.begin()));
end = fc::time_point::now();
wlog("public_key_type proper comparion: ${rounds} rounds in ${ms} ms",
("rounds", rounds)("ms", (end-start).count()/1000));
}
Output:
83440ms th_a performance_tests.cpp:67 test_method ] public_key_type default comparion: 1000000 rounds in 5637 ms
83772ms th_a performance_tests.cpp:75 test_method ] public_key_type proper comparion: 1000000 rounds in 332 ms
PBSA / Developer tasks
Bug Description
public_key_typehas nooperator<implementation, but it can be implicitly converted toaddress(at the cost of a SHA512 calculation) which does. Thus anysetormapkeyed onpublic_key_typedoes two SHA512 calculations peroperator<call. This is ridiculously slow.Impacts
Describe which portion(s) of Peerplays may be impacted by this bug. Please tick at least one box.
Additional Context (optional)
Benching code:
Output:
PBSA / Developer tasks