Skip to content

Commit 4c6f003

Browse files
committed
fw: remove pit unsafe gc optimizations
1 parent 62d4ca8 commit 4c6f003

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

fw/table/pit-cs-tree.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type pitCsTreeNode struct {
6161
// NewPitCS creates a new combined PIT-CS for a forwarding thread.
6262
func NewPitCS(onExpiration OnPitExpiration) *PitCsTree {
6363
pitCs := new(PitCsTree)
64-
pitCs.root = PitCsPools.PitCsTreeNode.Get()
64+
pitCs.root = PitCsPools.PitCsTreeNode.New()
6565
pitCs.root.component = enc.Component{} // zero component
6666
pitCs.onExpiration = onExpiration
6767
pitCs.pitTokens = make([]*nameTreePitEntry, pitTokenLookupTableSize)
@@ -168,8 +168,11 @@ func (p *PitCsTree) RemoveInterest(pitEntry PitEntry) bool {
168168
entry.node.pruneIfEmpty()
169169
p.nPitEntries--
170170

171-
// leave the entry in the token table, but mark it as invalid
172-
// this stops it from being garbage collected and makes pool effective
171+
// remove entry from pit token lookup table
172+
tokIdx := p.pitTokenIdx(entry.Token())
173+
if p.pitTokens[tokIdx] == entry {
174+
p.pitTokens[tokIdx] = nil
175+
}
173176

174177
// now it is invalid to use the entry
175178
entry.encname = nil // invalidate
@@ -307,8 +310,8 @@ func (p *pitCsTreeNode) getChildrenCount() int {
307310
func (p *pitCsTreeNode) pruneIfEmpty() {
308311
for curNode := p; curNode.parent != nil && curNode.getChildrenCount() == 0 &&
309312
len(curNode.pitEntries) == 0 && curNode.csEntry == nil; curNode = curNode.parent {
310-
PitCsPools.PitCsTreeNode.Put(curNode)
311313
delete(curNode.parent.children, curNode.component.Hash())
314+
PitCsPools.PitCsTreeNode.Put(curNode)
312315
}
313316
}
314317

std/types/sync_pool/sync_pool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ func New[T any](init func() T, reset func(T)) SyncPool[T] {
1818
}
1919
}
2020

21+
// New creates a new object of type T.
22+
func (p *SyncPool[T]) New() T {
23+
val := p.pool.New().(T)
24+
p.reset(val)
25+
return val
26+
}
27+
2128
// Get returns a new T from the pool.
2229
func (p *SyncPool[T]) Get() T {
2330
val := p.pool.Get().(T)

0 commit comments

Comments
 (0)