Commit 3e9164b3 authored by Kirill Smelkov's avatar Kirill Smelkov

X rebuild: tests: Don't exercise keys from keys2 that already became tracked...

X rebuild: tests: Don't exercise keys from keys2 that already became tracked after Track(keys1) + Update

58s -> 14s  (in -short mode)
parent 7371f9c5
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
...@@ -973,9 +973,9 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -973,9 +973,9 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
t2.at: "at2", t2.at: "at2",
} }
fmt.Printf("@%s: %v\n", xat[t0.at], t0.xkv.Flatten()) //fmt.Printf("@%s: %v\n", xat[t0.at], t0.xkv.Flatten())
fmt.Printf("@%s: %v\n", xat[t1.at], t1.xkv.Flatten()) //fmt.Printf("@%s: %v\n", xat[t1.at], t1.xkv.Flatten())
fmt.Printf("@%s: %v\n", xat[t2.at], t2.xkv.Flatten()) //fmt.Printf("@%s: %v\n", xat[t2.at], t2.xkv.Flatten())
kadj10 := KAdj(t1,t0, allTestKeys(t0,t1,t2)) kadj10 := KAdj(t1,t0, allTestKeys(t0,t1,t2))
kadj21 := KAdj(t2,t1, allTestKeys(t0,t1,t2)) kadj21 := KAdj(t2,t1, allTestKeys(t0,t1,t2))
...@@ -1060,8 +1060,17 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -1060,8 +1060,17 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
/*trackSet=*/ Tkeys1R2, /*trackSet=*/ Tkeys1R2,
/*vδT=*/ δkv1_k1R2, δkv2_k1R2) /*vδT=*/ δkv1_k1R2, δkv2_k1R2)
// tRestKeys2 = tAllKeys - keys1 // tRestKeys2 = tAllKeys - keys1
tRestKeys2 := tAllKeys.Difference(keys1) // reduce that to = tAllKeys - keys1R2 in short mode
// ( if key from keys2 already became tracked after Track(keys1) + Update,
// adding Track(that-key), is not adding much testing coverage to recompute paths )
var tRestKeys2 SetKey
if testing.Short() {
tRestKeys2 = tAllKeys.Difference(keys1R2)
} else {
tRestKeys2 = tAllKeys.Difference(keys1)
}
tRestKeyv2 := tRestKeys2.SortedElements() tRestKeyv2 := tRestKeys2.SortedElements()
for k2idx := range IntSets(len(tRestKeyv2)) { for k2idx := range IntSets(len(tRestKeyv2)) {
keys2 := SetKey{} keys2 := SetKey{}
...@@ -1100,8 +1109,8 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -1100,8 +1109,8 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
// δkvX_k12R2 = tX.δxkv / keys12R2 // δkvX_k12R2 = tX.δxkv / keys12R2
δkv1_k12R2 := map[Key]Δstring{} δkv1_k12R2 := make(map[Key]Δstring, len(t1.δxkv))
δkv2_k12R2 := map[Key]Δstring{} δkv2_k12R2 := make(map[Key]Δstring, len(t2.δxkv))
for k := range keys12R2 { for k := range keys12R2 {
δv1, ok := t1.δxkv[k] δv1, ok := t1.δxkv[k]
if ok { if ok {
......
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