mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: make treap iteration more efficient
This change introduces a treapIterFilter type which represents the power set of states described by a treapIterType. This change then adds a treapIterFilter field to each treap node indicating the types of spans that live in that subtree. The field is maintained via the same mechanism used to maintain maxPages. This allows pred, succ, start, and end to be judicious about which subtrees it will visit, ensuring that iteration avoids traversing irrelevant territory. Without this change, repeated scavenging attempts can end up being N^2 as the scavenger walks over what it already scavenged before finding new spans available for scavenging. Finally, this change also only scavenges a span once it is removed from the treap. There was always an invariant that spans owned by the treap may not be mutated in-place, but with this change violating that invariant can cause issues with scavenging. For #30333. Change-Id: I8040b997e21c94a8d3d9c8c6accfe23cebe0c3d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/174878 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
9baa4301cf
commit
fa8470a8cd
4 changed files with 240 additions and 154 deletions
|
|
@ -546,15 +546,21 @@ func (s Span) Pages() uintptr {
|
|||
return s.mspan.npages
|
||||
}
|
||||
|
||||
type TreapIterType int
|
||||
type TreapIterType treapIterType
|
||||
|
||||
const (
|
||||
TreapIterScav TreapIterType = TreapIterType(treapIterScav)
|
||||
TreapIterBits = treapIterBits
|
||||
)
|
||||
|
||||
type TreapIterFilter treapIterFilter
|
||||
|
||||
func TreapFilter(mask, match TreapIterType) TreapIterFilter {
|
||||
return TreapIterFilter(treapFilter(treapIterType(mask), treapIterType(match)))
|
||||
}
|
||||
|
||||
func (s Span) MatchesIter(mask, match TreapIterType) bool {
|
||||
return s.mspan.matchesIter(treapIterType(mask), treapIterType(match))
|
||||
return treapFilter(treapIterType(mask), treapIterType(match)).matches(s.treapFilter())
|
||||
}
|
||||
|
||||
type TreapIter struct {
|
||||
|
|
@ -639,5 +645,5 @@ func (t *Treap) Size() int {
|
|||
|
||||
func (t *Treap) CheckInvariants() {
|
||||
t.mTreap.treap.walkTreap(checkTreapNode)
|
||||
t.mTreap.treap.validateMaxPages()
|
||||
t.mTreap.treap.validateInvariants()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue