Skip to content

Commit

Permalink
feat(blob/service): cover getByCommitment with benchmark (#3116)
Browse files Browse the repository at this point in the history
Added the benchmark for `getByCommitment`

`BenchmarkGetByCommitment-12 3139 380827 ns/op 701647 B/op 4990
allocs/op`


[profile.pdf](https://github.com/celestiaorg/celestia-node/files/13987571/profile.pdf)
  • Loading branch information
vgonkivs authored Jan 23, 2024
1 parent c173a1e commit dd18169
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,28 @@ func TestService_GetAllWithoutPadding(t *testing.T) {
require.NoError(t, err)
}

func createService(ctx context.Context, t *testing.T, blobs []*Blob) *Service {
// BenchmarkGetByCommitment-12 3139 380827 ns/op 701647 B/op 4990 allocs/op
func BenchmarkGetByCommitment(b *testing.B) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
b.Cleanup(cancel)
appBlobs, err := blobtest.GenerateV0Blobs([]int{32, 32}, true)
require.NoError(b, err)

blobs, err := convertBlobs(appBlobs...)
require.NoError(b, err)

service := createService(ctx, b, blobs)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.ReportAllocs()
_, _, err = service.getByCommitment(
ctx, 1, blobs[1].Namespace(), blobs[1].Commitment,
)
require.NoError(b, err)
}
}

func createService(ctx context.Context, t testing.TB, blobs []*Blob) *Service {
bs := ipld.NewMemBlockservice()
batching := ds_sync.MutexWrap(ds.NewMapDatastore())
headerStore, err := store.NewStore[*header.ExtendedHeader](batching)
Expand Down
2 changes: 1 addition & 1 deletion header/headertest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func RandBlockID(testing.TB) types.BlockID {
return bid
}

func ExtendedHeaderFromEDS(t *testing.T, height uint64, eds *rsmt2d.ExtendedDataSquare) *header.ExtendedHeader {
func ExtendedHeaderFromEDS(t testing.TB, height uint64, eds *rsmt2d.ExtendedDataSquare) *header.ExtendedHeader {
valSet, vals := RandValidatorSet(10, 10)
gen := RandRawHeader(t)
dah, err := share.NewRoot(eds)
Expand Down

0 comments on commit dd18169

Please sign in to comment.