Repository navigation
Conversation
|
Personally I find the existing version easier to reason about. I think I'd prefer leaving this as-is, especially considering that this is consensus critical code :) |
promag
left a comment
There was a problem hiding this comment.
Did you compare the benchmark before and after?
There was a problem hiding this comment.
There are two optimizations included here:
- stop wasting computation time once mutated gets set
- use the parameter value directly instead of local copy
While the second saves one compare+assign operation and might be insignificant, the first effectively saves useless processing as the result is already known.
To me it is not only optimization but causing a trigger that something was forgotten when reading the code.
@practicalswift : would you support @promag's suggestion to limit the proposal to include only the first part, which would limit the change to one line and gain the most potential savings, or do you oppose the change generally?
|
Does this improve IBD speed significantly? Otherwise it might not be worth it the review effort. |
In ComputeMerkleRoot, the mutated flag is only set to true but never becomes false thereafter. Therefore all following tests after it became true are wasted computation. Fix this by doing the tests only while the flag is false. Signed-off-by: Zefir Kurtisi <[email protected]>
I reduced the change to the relevant (one-line) part, which should be trivial to review. Maybe the overall speed improvement is not significant, but the local is obvious: if the rightest-most bottom-leaf is a copy, the flag becomes true immediately, but the (then waste) checks continue for every next level up to the root. As kernel developer I might be more waste sensitive than required here, so if you think it is not worth it, I'm fine with closing - and sorry for noise. |
promag
left a comment
There was a problem hiding this comment.
I don't see significant gains. I've even tried other tweaks with the same result:
tweak 1 - break loop if more iterations aren't needed
if (hashes[pos] == hashes[pos + 1]) {
mutation = true;
break;
}
tweak 2: - check mutated once:
if (mutated) {
while (hashes.size() > 1) {
// …
}
} else {
while (hashes.size() > 1) {
// …
}
}
Thanks, the hashing cost in fact is so dominant that the comparison operation remains below measurement accuracy: ... not worth it. |
In ComputeMerkleRoot, the mutated flag is only set to
true but never becomes false thereafter. Therefore
all following tests after it became true are wasted
computation. Fix this by doing the tests only while
the flag is false.
While at that, drop the temporary local variable and
use the provided parameter in place.
Signed-off-by: Zefir Kurtisi [email protected]