Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion part/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,26 @@ func (txn *Txn[T]) Commit() Tree[T] {
return t
}

// watchesReuseThreshold is the threshold at which the [txn.watches] hash
// map is reused for next transaction.
const watchesReuseThreshold = 64

// Notify closes the watch channels of nodes that were
// mutated as part of this transaction. Must be called before
// Tree.Txn() is used again.
func (txn *Txn[T]) Notify() {
for ch := range txn.watches {
close(ch)
}
clear(txn.watches)
if !txn.dirty && len(txn.watches) > 0 {
panic("BUG: watch channels marked but txn not dirty")
}
// Clear or reallocate the watches hash map for the next transaction.
if len(txn.watches) <= watchesReuseThreshold {
clear(txn.watches)
} else {
txn.watches = make(map[chan struct{}]struct{})
}
if txn.dirty && txn.rootWatch != nil {
close(txn.rootWatch)
txn.rootWatch = nil
Expand Down