Skip to content

Commit

Permalink
fw: remove pit unsafe gc optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Feb 4, 2025
1 parent 62d4ca8 commit 4c6f003
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fw/table/pit-cs-tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type pitCsTreeNode struct {
// NewPitCS creates a new combined PIT-CS for a forwarding thread.
func NewPitCS(onExpiration OnPitExpiration) *PitCsTree {
pitCs := new(PitCsTree)
pitCs.root = PitCsPools.PitCsTreeNode.Get()
pitCs.root = PitCsPools.PitCsTreeNode.New()
pitCs.root.component = enc.Component{} // zero component
pitCs.onExpiration = onExpiration
pitCs.pitTokens = make([]*nameTreePitEntry, pitTokenLookupTableSize)
Expand Down Expand Up @@ -168,8 +168,11 @@ func (p *PitCsTree) RemoveInterest(pitEntry PitEntry) bool {
entry.node.pruneIfEmpty()
p.nPitEntries--

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

// now it is invalid to use the entry
entry.encname = nil // invalidate
Expand Down Expand Up @@ -307,8 +310,8 @@ func (p *pitCsTreeNode) getChildrenCount() int {
func (p *pitCsTreeNode) pruneIfEmpty() {
for curNode := p; curNode.parent != nil && curNode.getChildrenCount() == 0 &&
len(curNode.pitEntries) == 0 && curNode.csEntry == nil; curNode = curNode.parent {
PitCsPools.PitCsTreeNode.Put(curNode)
delete(curNode.parent.children, curNode.component.Hash())
PitCsPools.PitCsTreeNode.Put(curNode)
}
}

Expand Down
7 changes: 7 additions & 0 deletions std/types/sync_pool/sync_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func New[T any](init func() T, reset func(T)) SyncPool[T] {
}
}

// New creates a new object of type T.
func (p *SyncPool[T]) New() T {
val := p.pool.New().(T)
p.reset(val)
return val
}

// Get returns a new T from the pool.
func (p *SyncPool[T]) Get() T {
val := p.pool.Get().(T)
Expand Down

0 comments on commit 4c6f003

Please sign in to comment.