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
Replace std::map with std::unordered_map. #679
Replace std::map with std::unordered_map. #679
Conversation
1d8ebd5
to
093b2db
Compare
That 64 bit hash requires a test or research. Is it just a hash for hash table implementation and then the hash table handles collisions by comparing full key or is the 64 bit key directly used as key to the map? |
Seems to be the former:
http://www.cplusplus.com/reference/unordered_map/unordered_map/ I will verify this just to be sure. |
look forward to testing this one. good work. |
Test program with same hash for different keys:
|
093b2db
to
28161e3
Compare
28161e3
to
eb79917
Compare
Updated with some benchmarks. If everyone is ok with a little more RAM usage I think we should include this in the version after the current mandatory. |
ee641e5
to
060f496
Compare
Fixed - Fixes for displaying on high DPI displays, #517 (@skcin). - Re-enable unit tests, add unit test to Travis, #769, #808 (@TheCharlatan). - Fix empty string in sendalert2 (@tomasbrod). Added - Neural Report RPC command, #1063 (@tomasbrod). - GUI wallet redign with new icons and purple native style (@skcin). Changed - Switch to autotools and Depends from Bitcoin, #487 (@TheCharlatan). - Clean and update docs for new build system, remove outdated, #828 (@TheCharlatan). - Change estimated time to stake calculations to be more accurate, #1084 (@jamescowens). - Move logging to tinyformat, #1009 (@TheCharlatan). - Improve appcache performance, #734 (@denravonska). - Improve block index memory access performance, #679 (@denravonska). - NN fixes: clean logging, explain mag single response, move contract to ndata_nresp (@denravonska) - Updated translations: - Turkish, #771 (@confuest). - Chinese, #1012 (@linnaea). - RPC refactor: Cleaner locks, better error handling, move execute calls to straght rpc calls, #1024 (@Foggyx420). - Change locking primitives from Boost to STL, #1029 (@Foggyx420). Removed - gridcoindiagnostic RPC call (@denravonska). - Galaza, #945 (@barton2526). - Assertion in SignSignature, #998 (@TheCharlatan). - Upgrade menu, #1094 (@jamescowens). - Acid test functions, #871 (@tomasbrod). - Qt4 support, #801 (@denravonska).
…eadseq PiperOrigin-RevId: 246668103
This pulls the
std::map
->std::unordered_map
change from Bitcoin. The benefit is that unordered map is almost always faster in all aspects, plus it makes the code a bit more readable.CPU usage
The CPU usage is drastically reduced. I did some profiling when syncing to see how much time was spent comparing
uint256
when locating blocks in the maps while syncing on a Raspberry Pi:As we can see, even though the
std::map
did fewer iterations due to shorter sync time and thus having its results skewed byscrypt
operations, it still consumed far more CPU cycles than theunordered_map
version.Memory usage
There is a slight memory usage increase with unordered_map:
I think this can be optimized away by improving
CBlockIndex
.Remaining