Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve requesting frontier performance #1503
On an MSVC Release build I profiled bootstrapping a fresh node for 30 seconds (chosen arbitrarily) to see if there was anything obvious which easily be improved. I found that 7% of the time was spent inside rai::uint256_union::number() when requesting frontiers.
There is a boost function boost::multiprecision::import_bits() which takes a sequence of bytes and constructs the appropriate multiprecision number (and conversely export_bits() to do the opposite). I tried using this instead and there was a small performance improvement. Next I looked at the callers and the majority were from the less than operator rai::uint256_union::operator<. Inside it, it calls number() on each operand and does the comparison with the result. However I think this step is unnecessary, and the bytes can be compared directly with std::memcmp. Results shown below (time spent inside operator<):
The numbers are even greater on a debug build (sometimes as high as 20% in the current build). While the import_bits() function change no longer affects this specific result, I have left it in as it is still beneficial. I also modified the *_union constructors to call export_bits to modify the bytes array with the passed in number. Some tests have been added to cover the changes to operator<.