From 6ac19b433000b8c1835427a0848e8c372d6f3938 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 1 Aug 2025 14:19:09 +0200 Subject: [PATCH] graph/db: cover more DB methods in benchmark test So that we can properly measure upcoming performance improvements. --- graph/db/benchmark_test.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/graph/db/benchmark_test.go b/graph/db/benchmark_test.go index 1d9a782fc..f1366459b 100644 --- a/graph/db/benchmark_test.go +++ b/graph/db/benchmark_test.go @@ -19,6 +19,8 @@ import ( "github.com/lightningnetwork/lnd/kvdb/postgres" "github.com/lightningnetwork/lnd/kvdb/sqlbase" "github.com/lightningnetwork/lnd/kvdb/sqlite" + "github.com/lightningnetwork/lnd/lnwire" + "github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/sqldb" "github.com/stretchr/testify/require" "golang.org/x/time/rate" @@ -643,6 +645,10 @@ func BenchmarkGraphReadMethods(b *testing.B) { nativeSQLPostgresConn, } + // We use a counter to make sure that any call-back is doing something + // useful, otherwise the compiler may optimize it away in the future. + var counter int64 + tests := []struct { name string fn func(b testing.TB, store V1Store) @@ -652,6 +658,11 @@ func BenchmarkGraphReadMethods(b *testing.B) { fn: func(b testing.TB, store V1Store) { err := store.ForEachNode( ctx, func(_ NodeRTx) error { + // Increment the counter to + // ensure the callback is doing + // something. + counter++ + return nil }, func() {}, ) @@ -667,6 +678,11 @@ func BenchmarkGraphReadMethods(b *testing.B) { _ *models.ChannelEdgePolicy, _ *models.ChannelEdgePolicy) error { + // Increment the counter to + // ensure the callback is doing + // something. + counter++ + return nil }, func() {}, ) @@ -682,6 +698,43 @@ func BenchmarkGraphReadMethods(b *testing.B) { require.NoError(b, err) }, }, + { + name: "ForEachNodeCacheable", + fn: func(b testing.TB, store V1Store) { + err := store.ForEachNodeCacheable( + ctx, func(_ route.Vertex, + _ *lnwire.FeatureVector) error { + + // Increment the counter to + // ensure the callback is doing + // something. + counter++ + + return nil + }, func() {}, + ) + require.NoError(b, err) + }, + }, + { + name: "ForEachNodeCached", + fn: func(b testing.TB, store V1Store) { + //nolint:ll + err := store.ForEachNodeCached( + ctx, func(route.Vertex, + map[uint64]*DirectedChannel) error { + + // Increment the counter to + // ensure the callback is doing + // something. + counter++ + + return nil + }, func() {}, + ) + require.NoError(b, err) + }, + }, } for _, test := range tests {