Skip to content

Conversation

@jrick
Copy link
Member

@jrick jrick commented Jan 26, 2026

Sum(nil) creates an unnecessary heap allocation appending the digest to the nil slice. Replace these calls with direct calls to the (*blake256.Hasher256).Sum256 method to avoid unnecessary allocations and copies.

@davecgh davecgh added this to the 2.2.0 milestone Jan 26, 2026
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes. Glad to see the new zero-alloc blake256 API getting some use.

@jrick jrick force-pushed the sum256 branch 3 times, most recently from c395171 to 0a13a76 Compare January 26, 2026 17:40
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Versus master:

name                       old alloc/op   new alloc/op   delta
----------------------------------------------------------------------------------
SignUtxoProof              1.06kB ± 0%    1.02kB ± 0%     -3.03%  (p=0.000 n=10+10)
ValidateSecp256k1P2PKH      192B ± 0%      160B ± 0%     -16.67%  (p=0.000 n=10+10)

name                       old allocs/op  new allocs/op  delta
-----------------------------------------------------------------------------------
SignUtxoProof               18.0 ± 0%      17.0 ± 0%      -5.56%  (p=0.000 n=10+10)
ValidateSecp256k1P2PKH      3.00 ± 0%      2.00 ± 0%     -33.33%  (p=0.000 n=10+10)

Sum(nil) creates an unnecessary heap allocation appending the digest to the
nil slice.  Replace these calls with direct calls to the
(*blake256.Hasher256).Sum256 method to avoid unnecessary allocations and
copies.

While here, use the hasher's specialized Write* methods in the utxoproof
package to improve readability.
@davecgh davecgh merged commit 9d9a412 into decred:master Jan 26, 2026
34 checks passed
@jrick jrick deleted the sum256 branch January 26, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants