lib/logstorage: avoid calling columnsHeader.initFromBlockHeader() multiple times for the same blockSearch

This should improve performance when blockSearch.getColumnsHeader() is called multiple times
from different places of the code.
This commit is contained in:
Aliaksandr Valialkin 2024-10-13 12:56:08 +02:00
parent 200d723b9a
commit 9e48074b59
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -113,13 +113,10 @@ type blockSearch struct {
// sbu is used for unmarshaling local columns
sbu stringsBlockUnmarshaler
// cshCached is the columnsHeader associated with the given block
// cshCache is the columnsHeader associated with the given block
//
// it is initialized lazily by calling getColumnsHeader().
cshCached columnsHeader
// cshInitialized is set to true if cshCached is initialized.
cshInitialized bool
cshCache *columnsHeader
// a is used for storing unmarshaled data in cshCached
a arena
@ -152,8 +149,10 @@ func (bs *blockSearch) reset() {
bs.sbu.reset()
bs.cshCached.reset()
bs.cshInitialized = false
if bs.cshCache != nil {
putColumnsHeader(bs.cshCache)
bs.cshCache = nil
}
bs.a.reset()
@ -190,10 +189,11 @@ func (bs *blockSearch) search(bsw *blockSearchWork, bm *bitmap) {
}
func (bs *blockSearch) getColumnsHeader() *columnsHeader {
if !bs.cshInitialized {
bs.cshCached.initFromBlockHeader(&bs.a, bs.bsw.p, &bs.bsw.bh)
if bs.cshCache == nil {
bs.cshCache = getColumnsHeader()
bs.cshCache.initFromBlockHeader(&bs.a, bs.bsw.p, &bs.bsw.bh)
}
return &bs.cshCached
return bs.cshCache
}
func (csh *columnsHeader) initFromBlockHeader(a *arena, p *part, bh *blockHeader) {