eventstore/mmm: use sync.Pool for tempResults.

This commit is contained in:
fiatjaf
2026-03-28 11:22:39 -03:00
parent 172e7890b9
commit d4940c7858
+9 -1
View File
@@ -7,6 +7,7 @@ import (
"log"
"math"
"slices"
"sync"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
@@ -14,6 +15,12 @@ import (
"github.com/PowerDNS/lmdb-go/lmdb"
)
var tempResultsPool = sync.Pool{
New: func() any {
return make([]nostr.Event, 0, 64)
},
}
// GetByID returns the event -- if found in this mmm -- and all the IndexingLayers it belongs to.
func (b *MultiMmapManager) GetByID(id nostr.ID) (*nostr.Event, IndexingLayers) {
var event *nostr.Event
@@ -140,7 +147,8 @@ func (il *IndexingLayer) query(txn *lmdb.Txn, filter nostr.Filter, limit int, yi
numberOfIteratorsToPullOnEachRound := max(1, int(math.Ceil(float64(len(iterators))/float64(12))))
totalEventsEmitted := 0
tempResults := make([]nostr.Event, 0, batchSizePerQuery*2)
tempResults := tempResultsPool.Get().([]nostr.Event)
defer tempResultsPool.Put(tempResults[:0])
for len(iterators) > 0 {
// reset stuff