Skip to content

Commit

Permalink
core/rawdb: add bench for decoding into rlpLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Sep 8, 2021
1 parent 6ae2cfc commit 7edca90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/rawdb/accessors_chain.go
Expand Up @@ -673,7 +673,8 @@ type storedReceiptRLP struct {
}

// ReceiptLogs is a barebone version of ReceiptForStorage which only keeps
// the list of logs.
// the list of logs. When decoding a stored receipt into this object we
// avoid creating the bloom filter.
type receiptLogs struct {
Logs []*types.Log
}
Expand Down
26 changes: 26 additions & 0 deletions core/rawdb/accessors_chain_test.go
Expand Up @@ -857,3 +857,29 @@ func TestDeriveLogFields(t *testing.T) {
}
}
}

func BenchmarkDecodeRLPLogs(b *testing.B) {
// Encoded receipts from block 0x14ee094309fbe8f70b65f45ebcc08fb33f126942d97464aad5eb91cfd1e2d269
buf, err := ioutil.ReadFile("testdata/stored_receipts.bin")
if err != nil {
b.Fatal(err)
}
b.Run("ReceiptForStorage", func(b *testing.B) {
b.ReportAllocs()
var r []*types.ReceiptForStorage
for i := 0; i < b.N; i++ {
if err := rlp.DecodeBytes(buf, &r); err != nil {
b.Fatal(err)
}
}
})
b.Run("rlpLogs", func(b *testing.B) {
b.ReportAllocs()
var r []*receiptLogs
for i := 0; i < b.N; i++ {
if err := rlp.DecodeBytes(buf, &r); err != nil {
b.Fatal(err)
}
}
})
}
Binary file added core/rawdb/testdata/stored_receipts.bin
Binary file not shown.

0 comments on commit 7edca90

Please sign in to comment.