Commit 7371f9c5 authored by Kirill Smelkov's avatar Kirill Smelkov

X rebuild: tests: Inline _assertTrack

t.Helper() is relatively expensive

61s -> 58s
parent 01433e96
To reduce allocs -> no change in t
diff --git a/wcfs/internal/xbtree/pptreesubset.go b/wcfs/internal/xbtree/pptreesubset.go
index 43bd37e5..d8c15d9b 100644
--- a/wcfs/internal/xbtree/pptreesubset.go
+++ b/wcfs/internal/xbtree/pptreesubset.go
@@ -77,7 +77,7 @@ func (S PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
panicf("node %s is not in the set <- %v", oid, path)
}
- path = append([]zodb.Oid{oid}, path...)
+ path = append(path, oid) // in reverse
oid = t.parent
if oid == zodb.InvalidOid {
@@ -85,6 +85,11 @@ func (S PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
}
}
+ // we've built path in reverse order - revert it back
+ for i, j := 0, len(path)-1; i<j; i, j = i+1, j-1 {
+ path[i], path[j] = path[j], path[i]
+ }
+
return path
}
To reduce allocs -> no change in t
diff --git a/wcfs/internal/xbtree/pptreesubset.go b/wcfs/internal/xbtree/pptreesubset.go
index 43bd37e5..b304a2d0 100644
--- a/wcfs/internal/xbtree/pptreesubset.go
+++ b/wcfs/internal/xbtree/pptreesubset.go
@@ -52,7 +52,7 @@ const debugPPSet = false
// Every node in the set comes with .parent pointer.
//
// XXX we only allow single parent/root case and report "tree corrupt" otherwise.
-type PPTreeSubSet map[zodb.Oid]*nodeInTree
+type PPTreeSubSet map[zodb.Oid]nodeInTree // NOTE _not_ *nodeInTree to reduce preesure on GC
// nodeInTree represents tracking information about a node.
// XXX -> treeNode ?
@@ -77,7 +77,7 @@ func (S PPTreeSubSet) Path(oid zodb.Oid) (path []zodb.Oid) {
panicf("node %s is not in the set <- %v", oid, path)
}
- path = append([]zodb.Oid{oid}, path...)
+ path = append([]zodb.Oid{oid}, path...) // XXX less copy/alloc
oid = t.parent
if oid == zodb.InvalidOid {
@@ -106,7 +106,6 @@ func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
// go through path and add nodes to the set
parent := zodb.InvalidOid
- var pt *nodeInTree = nil
for _, oid := range path {
if oid == zodb.InvalidOid {
panicf("path has node with invalid oid: %v", path)
@@ -114,7 +113,7 @@ func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
t, already := S[oid]
if !already {
- t = &nodeInTree{parent: parent, nchild: 0}
+ t = nodeInTree{parent: parent, nchild: 0}
S[oid] = t
}
if t.parent != parent {
@@ -123,12 +122,13 @@ func (S PPTreeSubSet) AddPath(path []zodb.Oid) {
oid, t.parent, parent)
}
- if pt != nil && !already {
+ if parent != zodb.InvalidOid && !already {
+ pt := S[parent]
pt.nchild++
+ S[parent] = pt
}
parent = oid
- pt = t
}
}
@@ -226,7 +226,7 @@ func (A PPTreeSubSet) xUnionInplace(B PPTreeSubSet) {
for oid, t2 := range B {
t, already := A[oid]
if !already {
- t = &nodeInTree{parent: t2.parent, nchild: 0}
+ t = nodeInTree{parent: t2.parent, nchild: 0}
A[oid] = t
// remember to nchild++ in parent
if t.parent != zodb.InvalidOid {
@@ -306,6 +306,7 @@ func (A PPTreeSubSet) xfixup(sign int, δnchild map[zodb.Oid]int) {
for oid, δnc := range δnchild {
t := A[oid] // t != nil as A is PP-connected
t.nchild += sign*δnc
+ A[oid] = t
if t.nchild == 0 {
gcq = append(gcq, oid)
}
@@ -332,6 +333,7 @@ func (S PPTreeSubSet) gc1(oid zodb.Oid) {
for oid != zodb.InvalidOid {
t := S[oid]
t.nchild--
+ S[oid] = t
if t.nchild > 0 {
break
}
@@ -398,7 +400,7 @@ func (S PPTreeSubSet) verify() {
func (orig PPTreeSubSet) Clone() PPTreeSubSet {
klon := make(PPTreeSubSet, len(orig))
for oid, t := range orig {
- klon[oid] = &nodeInTree{parent: t.parent, nchild: t.nchild}
+ klon[oid] = nodeInTree{parent: t.parent, nchild: t.nchild}
}
return klon
}
diff --git a/wcfs/internal/xbtree/δbtail_test.go b/wcfs/internal/xbtree/δbtail_test.go
index ad4b4a13..4d9b126d 100644
--- a/wcfs/internal/xbtree/δbtail_test.go
+++ b/wcfs/internal/xbtree/δbtail_test.go
@@ -359,7 +359,7 @@ func (rbs RBucketSet) _trackSetWithCov(tracked SetKey, outKeyCover *RangedKeySet
if kb.oid != zodb.InvalidOid {
track, already := trackSet[kb.oid]
if !already {
- track = &nodeInTree{parent: kb.parent.oid, nchild: 0}
+ track = nodeInTree{parent: kb.parent.oid, nchild: 0}
trackSet[kb.oid] = track
newNode = true
}
@@ -378,7 +378,7 @@ func (rbs RBucketSet) _trackSetWithCov(tracked SetKey, outKeyCover *RangedKeySet
newParent := false
pt, already := trackSet[p.oid]
if !already {
- pt = &nodeInTree{parent: ppoid, nchild: 0}
+ pt = nodeInTree{parent: ppoid, nchild: 0}
trackSet[p.oid] = pt
newParent = true
}
@@ -388,6 +388,7 @@ func (rbs RBucketSet) _trackSetWithCov(tracked SetKey, outKeyCover *RangedKeySet
if newNode {
pt.nchild++
+ trackSet[p.oid] = pt
}
newNode = newParent
p = p.parent
...@@ -911,22 +911,14 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod ...@@ -911,22 +911,14 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
} }
} }
// assertTrack verifies that trackSet == trackSetOK.
// XXX place
// XXX inline into δbtail.assertTrack?
func _assertTrack(t *testing.T, subj string, trackSet, trackSetOK PPTreeSubSet) {
t.Helper()
if !trackSet.Equal(trackSetOK) {
t.Errorf("%s:\n\thave: %v\n\twant: %v", subj, trackSet, trackSetOK)
}
}
// assertTrack verifies state of .trackSet and ΔTtail.trackNew. // assertTrack verifies state of .trackSet and ΔTtail.trackNew.
// it assumes that only one tree root is being tracked. // it assumes that only one tree root is being tracked.
// XXX place // XXX place
func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK PPTreeSubSet, trackNewOK PPTreeSubSet) { func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK PPTreeSubSet, trackNewOK PPTreeSubSet) {
t.Helper() t.Helper()
_assertTrack(t, subj + ": trackSet", δBtail.trackSet, trackSetOK) if !δBtail.trackSet.Equal(trackSetOK) {
t.Errorf("%s: trackSet:\n\thave: %v\n\twant: %v", subj, δBtail.trackSet, trackSetOK)
}
roots := SetOid{} roots := SetOid{}
for root := range δBtail.vδTbyRoot { for root := range δBtail.vδTbyRoot {
...@@ -958,7 +950,9 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK PPTree ...@@ -958,7 +950,9 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK PPTree
t.Errorf("%s: trackNewRoots:\n\thave: %v\n\twant: %v", subj, δBtail.trackNewRoots, trackNewRootsOK) t.Errorf("%s: trackNewRoots:\n\thave: %v\n\twant: %v", subj, δBtail.trackNewRoots, trackNewRootsOK)
} }
_assertTrack(t, subj + ": vδT.trackNew", δTtail.trackNew, trackNewOK) if !δTtail.trackNew.Equal(trackNewOK) {
t.Errorf("%s: vδT.trackNew:\n\thave: %v\n\twant: %v", subj, δTtail.trackNew, trackNewOK)
}
} }
// xverifyΔBTail_rebuild verifies ΔBtail.rebuild during t0->t1->t2 transition. // xverifyΔBTail_rebuild verifies ΔBtail.rebuild during t0->t1->t2 transition.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment