Commit dd6ce1db authored by Kirill Smelkov's avatar Kirill Smelkov

X δbtail: tests: Tweaks to run rebuild tests faster

        $ time go test -failfast -short -run 'ΔBTail/rebuild' >x

before:

        real    0m17,852s
        user    0m23,068s
        sys     0m1,825s

after:

        real    0m9,622s
        user    0m12,515s
        sys     0m1,274s
parent d4a523b2
...@@ -59,7 +59,14 @@ func (s Set) Elements() []VALUE { ...@@ -59,7 +59,14 @@ func (s Set) Elements() []VALUE {
// Union returns s t // Union returns s t
func (s Set) Union(t Set) Set { func (s Set) Union(t Set) Set {
u := Set{} // l = max(len(s), len(t))
l := len(s)
if lt := len(t); lt > l {
l = lt
}
u := make(Set, l)
for v := range s { for v := range s {
u.Add(v) u.Add(v)
} }
......
...@@ -61,7 +61,14 @@ func (s SetBigFile) Elements() []*BigFile { ...@@ -61,7 +61,14 @@ func (s SetBigFile) Elements() []*BigFile {
// Union returns s ∪ t // Union returns s ∪ t
func (s SetBigFile) Union(t SetBigFile) SetBigFile { func (s SetBigFile) Union(t SetBigFile) SetBigFile {
u := SetBigFile{} // l = max(len(s), len(t))
l := len(s)
if lt := len(t); lt > l {
l = lt
}
u := make(SetBigFile, l)
for v := range s { for v := range s {
u.Add(v) u.Add(v)
} }
......
...@@ -61,7 +61,14 @@ func (s SetI64) Elements() []int64 { ...@@ -61,7 +61,14 @@ func (s SetI64) Elements() []int64 {
// Union returns s ∪ t // Union returns s ∪ t
func (s SetI64) Union(t SetI64) SetI64 { func (s SetI64) Union(t SetI64) SetI64 {
u := SetI64{} // l = max(len(s), len(t))
l := len(s)
if lt := len(t); lt > l {
l = lt
}
u := make(SetI64, l)
for v := range s { for v := range s {
u.Add(v) u.Add(v)
} }
......
...@@ -61,7 +61,14 @@ func (s SetOid) Elements() []Oid { ...@@ -61,7 +61,14 @@ func (s SetOid) Elements() []Oid {
// Union returns s ∪ t // Union returns s ∪ t
func (s SetOid) Union(t SetOid) SetOid { func (s SetOid) Union(t SetOid) SetOid {
u := SetOid{} // l = max(len(s), len(t))
l := len(s)
if lt := len(t); lt > l {
l = lt
}
u := make(SetOid, l)
for v := range s { for v := range s {
u.Add(v) u.Add(v)
} }
......
...@@ -451,28 +451,35 @@ func NewΔBtail(at0 zodb.Tid, db *zodb.DB) *ΔBtail { ...@@ -451,28 +451,35 @@ func NewΔBtail(at0 zodb.Tid, db *zodb.DB) *ΔBtail {
// xverifyΔBTail_rebuild needs ΔBTree.clone because otherwise it is too slow to run that test. // xverifyΔBTail_rebuild needs ΔBTree.clone because otherwise it is too slow to run that test.
func (orig *ΔBtail) clone() *ΔBtail { func (orig *ΔBtail) clone() *ΔBtail {
klon := NewΔBtail(orig.Tail(), orig.db) klon := &ΔBtail{db: orig.db}
// δZtail // δZtail
klon.δZtail = zodb.NewΔTail(orig.Tail())
for _, δZ := range orig.δZtail.Data() { for _, δZ := range orig.δZtail.Data() {
klon.δZtail.Append(δZ.Rev, δZ.Changev) klon.δZtail.Append(δZ.Rev, δZ.Changev)
} }
// trackIdx // trackIdx
klon.trackIdx = make(trackIndex, len(orig.trackIdx))
for oid, t := range orig.trackIdx { for oid, t := range orig.trackIdx {
klon.trackIdx[oid] = &nodeTrack{parent: t.parent, nchild: t.nchild} klon.trackIdx[oid] = &nodeTrack{parent: t.parent, nchild: t.nchild}
} }
// trackNew // trackNew
klon.trackNew = make(trackIndex, len(orig.trackNew))
for oid, t := range orig.trackNew { for oid, t := range orig.trackNew {
klon.trackNew[oid] = &nodeTrack{parent: t.parent, nchild: t.nchild} klon.trackNew[oid] = &nodeTrack{parent: t.parent, nchild: t.nchild}
} }
// byRoot // byRoot
klon.byRoot = make(map[zodb.Oid]*ΔTtail, len(orig.byRoot))
for root, origΔTtail := range orig.byRoot { for root, origΔTtail := range orig.byRoot {
klonΔTtail := &ΔTtail{} klonΔTtail := &ΔTtail{}
klonΔTtail.vδT = append(klonΔTtail.vδT, origΔTtail.vδT...) klonΔTtail.vδT = append(klonΔTtail.vδT, origΔTtail.vδT...)
klonΔTtail.KVAtTail = make(map[Key]Value, len(origΔTtail.KVAtTail))
for k, v := range origΔTtail.KVAtTail { for k, v := range origΔTtail.KVAtTail {
klonΔTtail.KVAtTail[k] = v klonΔTtail.KVAtTail[k] = v
} }
klonΔTtail.lastRevOf = make(map[Key]zodb.Tid, len(origΔTtail.lastRevOf))
for k, rev := range origΔTtail.lastRevOf { for k, rev := range origΔTtail.lastRevOf {
klonΔTtail.lastRevOf[k] = rev klonΔTtail.lastRevOf[k] = rev
} }
...@@ -480,8 +487,9 @@ func (orig *ΔBtail) clone() *ΔBtail { ...@@ -480,8 +487,9 @@ func (orig *ΔBtail) clone() *ΔBtail {
} }
// holeIdxByRoot // holeIdxByRoot
klon.holeIdxByRoot = make(map[zodb.Oid]treeSetKey, len(orig.holeIdxByRoot))
for root, origHoleIdx := range orig.holeIdxByRoot { for root, origHoleIdx := range orig.holeIdxByRoot {
klonHoleIdx := treeSetKey{SetKey{}} klonHoleIdx := treeSetKey{make(SetKey, len(origHoleIdx.SetKey))}
klonHoleIdx.Update(origHoleIdx.SetKey) klonHoleIdx.Update(origHoleIdx.SetKey)
klon.holeIdxByRoot[root] = klonHoleIdx klon.holeIdxByRoot[root] = klonHoleIdx
} }
...@@ -1617,7 +1625,7 @@ func vnode(node Node) string { ...@@ -1617,7 +1625,7 @@ func vnode(node Node) string {
case *Tree: kind = "T" case *Tree: kind = "T"
case *Bucket: kind = "B" case *Bucket: kind = "B"
} }
return fmt.Sprintf("%s%s", kind, node.POid()) return kind + node.POid().String()
} }
func (rn nodeInRange) String() string { func (rn nodeInRange) String() string {
......
...@@ -822,11 +822,34 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod ...@@ -822,11 +822,34 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
} }
} }
// equal returns whether a == b.
// XXX place
func (a trackIndex) equal(b trackIndex) bool {
if len(a) != len(b) {
return false
}
for oid, ta := range a {
tb, ok := b[oid]
if !ok {
return false
}
if !(ta.parent == tb.parent && ta.nchild == tb.nchild) {
return false
}
}
return true
}
// assertTrack verifies that trackIdx == trackIdxOK. // assertTrack verifies that trackIdx == trackIdxOK.
// XXX place // XXX place
func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) { func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) {
t.Helper() t.Helper()
if !reflect.DeepEqual(trackIdx, trackIdxOK) { // eq := reflect.DeepEqual(trackIdx, trackIdxOK) // slower
eq := trackIdx.equal(trackIdxOK)
if !eq {
t.Errorf("%s:\n\thave: %v\n\twant: %v", subj, trackIdx, trackIdxOK) t.Errorf("%s:\n\thave: %v\n\twant: %v", subj, trackIdx, trackIdxOK)
} }
} }
...@@ -899,7 +922,7 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -899,7 +922,7 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
/*trackIdx=*/ t1.xkv.trackIdx(keys1), /*trackIdx=*/ t1.xkv.trackIdx(keys1),
/*vδB=*/ /*XXX temp*/nil /*[δ1/Tadj(keys1)*/) /*vδB=*/ /*XXX temp*/nil /*[δ1/Tadj(keys1)*/)
t.Run(fmt.Sprintf(" →%s", t2.tree), func(t *testing.T) { t.Run((" →" + t2.tree), func(t *testing.T) {
// tracked keys1 becomes tracked keys1_2 after Update(t1->t2) // tracked keys1 becomes tracked keys1_2 after Update(t1->t2)
keys1_2 := kadj12.Map(keys1) keys1_2 := kadj12.Map(keys1)
xverifyΔBTail_rebuild_U(t, δbtail, t1, t2, xat, /*trackIdx=*/t2.xkv.trackIdx(keys1_2)) xverifyΔBTail_rebuild_U(t, δbtail, t1, t2, xat, /*trackIdx=*/t2.xkv.trackIdx(keys1_2))
...@@ -913,7 +936,8 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -913,7 +936,8 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
keys2.Add(tRestKeyv2[idx2]) keys2.Add(tRestKeyv2[idx2])
} }
t.Run(fmt.Sprintf(" T%s;R", keys2), func(t *testing.T) { // t.Run is expensive at this level of nest
// t.Run(" T"+keys2.String()+";R", func(t *testing.T) {
δbtail_ := δbtail.clone() δbtail_ := δbtail.clone()
xverifyΔBTail_rebuild_TR(t, db, δbtail_, t2, treeRoot, xat, xverifyΔBTail_rebuild_TR(t, db, δbtail_, t2, treeRoot, xat,
// after Track(keys2) // after Track(keys2)
...@@ -925,7 +949,7 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -925,7 +949,7 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
// after rebuild // after rebuild
/* trackIdx=*/ t2.xkv.trackIdx(keys1_2.Union(keys2)), /* trackIdx=*/ t2.xkv.trackIdx(keys1_2.Union(keys2)),
/*vδB=*/ /*XXX temp*/nil /*[δ1/keys1+keys2, δ2/keys1+keys2]*/) /*vδB=*/ /*XXX temp*/nil /*[δ1/keys1+keys2, δ2/keys1+keys2]*/)
}) // })
} }
}) })
}) })
......
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