go: Refactor for clarity and performance #34
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The core of the algorihm has been refactored for improved clarity. Magic numbers
were replaced by constants, and the code was reorganised to make it easier to
understand.
Previously the rehashing code for blocks were a collision was identified, had a
custom code with a duplicated logic from the core algorithm. This has now being
simplified, resulting in less code and a logic more aligned with what a goasm
implementation would look like.
When it was first implemented, all fields storing state needed for the collision
detection were kept in the digest struct. That was unnecessary, as such data
is only required during block processing, and therefore this commit removes them.
The storage of pre-step compression state has been optimised to use less memory.
The collision detection algorithm only need to access this data for specific
rounds of the SHA1 process which are linked to existing dvs, which at present
is for rounds: 0, 58 and 65.
If more dvs were to be added, targeting different rounds, those would need to
to be stored in memory as well. Note that the original algorithmn stores into
memory the data for the 80 rounds.
Likewise, during recompression, the original algorithm had additional steps to
account for dvs that did not make it into the final dvs set. Therefore, this has
been removed from the code.
The impact in
sec/op
and processB/s
can be seen below: