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.

(cherry picked from commit 9e48074b59)
This commit is contained in:
Aliaksandr Valialkin 2024-10-13 12:56:08 +02:00 committed by hagen1778
parent f7496c17e4
commit afe5158443
No known key found for this signature in database
GPG Key ID: E92986095E0DD614

View File

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