Skip to content

Commit

Permalink
completeLeafHash: to pass escape analysis (#12910)
Browse files Browse the repository at this point in the history
seems call to `completeLeafHash` didn't pass escape analysis and
highlited by pprof

<img width="1315" alt="Screenshot 2024-11-29 at 12 51 11"
src="https://github.com/user-attachments/assets/383e750e-78fd-423a-93a3-686a7bf914a5">
  • Loading branch information
AskAlexSharov authored Dec 2, 2024
1 parent 3f6f923 commit 10105c5
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions erigon-lib/commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,18 @@ func (cell *cell) accountForHashing(buffer []byte, storageRootHash [length.Hash]
return pos
}

func (hph *HexPatriciaHashed) completeLeafHash(buf, keyPrefix []byte, kp, kl, compactLen int, key []byte, compact0 byte, ni int, val rlp.RlpSerializable, singleton bool) ([]byte, error) {
func (hph *HexPatriciaHashed) completeLeafHash(buf []byte, compactLen int, key []byte, compact0 byte, ni int, val rlp.RlpSerializable, singleton bool) ([]byte, error) {
// Compute the total length of binary representation
var kp, kl int
var keyPrefix [1]byte
if compactLen > 1 {
keyPrefix[0] = 0x80 + byte(compactLen)
kp = 1
kl = compactLen
} else {
kl = 1
}

totalLen := kp + kl + val.DoubleRLPLen()
var lenPrefix [4]byte
pl := rlp.GenerateStructLen(lenPrefix[:], totalLen)
Expand Down Expand Up @@ -603,8 +614,6 @@ func (hph *HexPatriciaHashed) completeLeafHash(buf, keyPrefix []byte, kp, kl, co
}

func (hph *HexPatriciaHashed) leafHashWithKeyVal(buf, key []byte, val rlp.RlpSerializableBytes, singleton bool) ([]byte, error) {
// Compute the total length of binary representation
var kp, kl int
// Write key
var compactLen int
var ni int
Expand All @@ -616,20 +625,10 @@ func (hph *HexPatriciaHashed) leafHashWithKeyVal(buf, key []byte, val rlp.RlpSer
} else {
compact0 = 0x20
}
var keyPrefix [1]byte
if compactLen > 1 {
keyPrefix[0] = 0x80 + byte(compactLen)
kp = 1
kl = compactLen
} else {
kl = 1
}
return hph.completeLeafHash(buf, keyPrefix[:], kp, kl, compactLen, key, compact0, ni, val, singleton)
return hph.completeLeafHash(buf, compactLen, key, compact0, ni, val, singleton)
}

func (hph *HexPatriciaHashed) accountLeafHashWithKey(buf, key []byte, val rlp.RlpSerializable) ([]byte, error) {
// Compute the total length of binary representation
var kp, kl int
// Write key
var compactLen int
var ni int
Expand All @@ -649,15 +648,7 @@ func (hph *HexPatriciaHashed) accountLeafHashWithKey(buf, key []byte, val rlp.Rl
ni = 1
}
}
var keyPrefix [1]byte
if compactLen > 1 {
keyPrefix[0] = byte(128 + compactLen)
kp = 1
kl = compactLen
} else {
kl = 1
}
return hph.completeLeafHash(buf, keyPrefix[:], kp, kl, compactLen, key, compact0, ni, val, true)
return hph.completeLeafHash(buf, compactLen, key, compact0, ni, val, true)
}

func (hph *HexPatriciaHashed) extensionHash(key []byte, hash []byte) ([length.Hash]byte, error) {
Expand Down

0 comments on commit 10105c5

Please sign in to comment.