Skip to content

Commit

Permalink
pool visibileIter
Browse files Browse the repository at this point in the history
  • Loading branch information
aptend committed Jan 17, 2025
1 parent 6ac7a70 commit c8fab20
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/vm/engine/tae/catalog/object_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ func (l *ObjectList) WaitUntilCommitted(ts types.TS) {

// Iterator part

var _iterPool = sync.Pool{New: func() any {
return &VisibleCommittedObjectIt{}
}}

type VisibleCommittedObjectIt struct {
iter btree.IterG[*ObjectEntry]
curr *ObjectEntry
Expand All @@ -348,13 +352,12 @@ type VisibleCommittedObjectIt struct {
// 1. txn is mock txn, no waiting, only return committed non-dropped objects, used for status check

func (l *ObjectList) MakeVisibleCommittedObjectIt(txn txnif.TxnReader) *VisibleCommittedObjectIt {
it := _iterPool.Get().(*VisibleCommittedObjectIt)
tree := l.tree.Load()
it := tree.Iter()
return &VisibleCommittedObjectIt{
iter: it,
txn: txn,
isMockTxn: len(txn.GetCtx()) == 0,
}
it.iter = tree.Iter()
it.txn = txn
it.isMockTxn = len(txn.GetCtx()) == 0
return it
}

func (it *VisibleCommittedObjectIt) Next() bool {
Expand Down Expand Up @@ -401,6 +404,11 @@ func (it *VisibleCommittedObjectIt) Item() *ObjectEntry {

func (it *VisibleCommittedObjectIt) Release() {
it.iter.Release()
it.curr = nil
it.txn = nil
it.firstCalled = false
it.isMockTxn = false
_iterPool.Put(it)
}

// utils
Expand Down

0 comments on commit c8fab20

Please sign in to comment.