The existing code prior to this change updated the relevant fields in the header and called its own hash method which internally makes use of the existing writer interface based serialization and shared buffers to prevent a lot of allocations. That makes sense most places in the code, but it is really bad for concurrent performance in a tight mining loop. Thus, this significantly optimizes the CPU miner workers to instead remove all mutex contention by serializing the header once outside of the loop, directly updating the relevant bytes in the serialized data, using the allocation-free hash method to compute the hash from the serialized bytes directly, and finally updating the block template header when/if a solution is found. It also now makes use of the much more efficient primitives and uint256 packages instead of big integers to further reduce allocations and speed up the calculations. The net result is a major speedup when mining with a single core and nearly linear scalar with multiple cores. Concretely, prior to these changes, I was only seeing around 400-570 kh/s with 1 or 2 cores and mining on more cores actually made the performance worse due to the all of the contention. With these changes, I'm seeing around 1.2Mh/s on a single core and over 10MH/s with 10 cores. |
||
|---|---|---|
| .. | ||
| cpuminer.go | ||
| doc.go | ||
| log.go | ||
| README.md | ||
cpuminer
Package cpuminer provides facilities for solving blocks (mining) using the CPU.
Overview
This package is currently a work in progress. It works without issue since it is used in several of the integration tests, but the API is not really ready for public consumption as it has simply been refactored out of the main codebase for now.
License
Package cpuminer is licensed under the copyfree ISC License.