Skip to content

Commit a1a2a80

Browse files
committed
wip diff
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 6bbacce commit a1a2a80

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

chainexchange/pubsub.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package chainexchange
33
import (
44
"context"
55
"fmt"
6+
"runtime"
67
"sync"
78
"time"
89

@@ -266,7 +267,9 @@ func (p *PubSubChainExchange) cacheAsDiscoveredChain(ctx context.Context, cmsg M
266267
keysBatch := cmsg.Chain.KeysForPrefixes()
267268
for offset := cmsg.Chain.Len() - 1; offset >= 0 && ctx.Err() == nil; offset-- {
268269
prefix := cmsg.Chain.Prefix(offset)
269-
key := keysBatch[offset]
270+
//key := keysBatch[offset]
271+
runtime.KeepAlive(keysBatch)
272+
key := prefix.Key()
270273

271274
if portion, found := wanted.Peek(key); !found {
272275
// Not a wanted key; add it to discovered chains if they are not there already,
@@ -332,7 +335,9 @@ func (p *PubSubChainExchange) cacheAsWantedChain(ctx context.Context, cmsg Messa
332335
keysBatch := cmsg.Chain.KeysForPrefixes()
333336
for offset := cmsg.Chain.Len() - 1; offset >= 0 && ctx.Err() == nil; offset-- {
334337
prefix := cmsg.Chain.Prefix(offset)
335-
key := keysBatch[offset]
338+
//key := keysBatch[offset]
339+
runtime.KeepAlive(keysBatch)
340+
key := prefix.Key()
336341

337342
if portion, found := wanted.Peek(key); !found || portion.IsPlaceholder() {
338343
wanted.Add(key, &chainPortion{

merkle/merkle_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package merkle
33
import (
44
"encoding/hex"
55
"fmt"
6+
"runtime"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
@@ -131,3 +132,23 @@ func TestHashTreeGolden(t *testing.T) {
131132
}
132133
assert.Equal(t, expectedHex, batchResHash)
133134
}
135+
136+
func BenchmarkIndividualPrefix(b *testing.B) {
137+
K := 128
138+
inputs := generateInputs("golden", K)
139+
b.ResetTimer()
140+
for i := 0; i < b.N; i++ {
141+
for i := 1; i < len(inputs); i++ {
142+
runtime.KeepAlive(Tree(inputs[:i+1]))
143+
}
144+
}
145+
}
146+
147+
func BenchmarkBatchPrefix(b *testing.B) {
148+
K := 128
149+
inputs := generateInputs("golden", K)
150+
b.ResetTimer()
151+
for i := 0; i < b.N; i++ {
152+
runtime.KeepAlive(BatchTree(inputs))
153+
}
154+
}

0 commit comments

Comments
 (0)