Skip to content

Commit

Permalink
Fix Race and add more benchmark tests (#11)
Browse files Browse the repository at this point in the history
* reverse iterator init

* some fixes

* fix reverse iterator seaklowerbound

* fix tests

* fix track channels

* longest prefix on txn

* some fixes

* revisit

* todo revisit

* major code refactor

* some minor fixes

* add lru

* fix bugs

* added walk func

* add more tests

* some prog

* some progress track mutate

* some progress

* fix tests

* some optimizations

* some memory optimizations

* fix tests

* minor fixes

* some minor fixes

* some fixes

* fix delete prefix

* some fixes

* init stack

* fix seek lower bound

* clone

* fix watch

* fix clone bug

* some fixes for go mem db

* merge absl

* Fix race

* fix go mod

* fix race in add child
  • Loading branch information
absolutelightning committed May 21, 2024
1 parent d097dd7 commit 643e521
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
35 changes: 29 additions & 6 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,22 +1158,45 @@ func BenchmarkMixedOperations(b *testing.B) {
// Randomly choose an operation
switch rand.Intn(3) {
case 0:
art.Insert([]byte(key), j)
art, _, _ = art.Insert([]byte(key), j)
case 1:
art.Get([]byte(key))
case 2:
art.Delete([]byte(key))
art, _, _ = art.Delete([]byte(key))
}
}
}
}

func BenchmarkGroupedOperations(b *testing.B) {
dataset := generateDataset(datasetSize)
art := NewRadixTree[int]()

b.ResetTimer()
for i := 0; i < b.N; i++ {
// Insert all keys
for _, key := range dataset {
art, _, _ = art.Insert([]byte(key), 0)
}

// Search all keys
for _, key := range dataset {
art.Get([]byte(key))
}

// Delete all keys
for _, key := range dataset {
art, _, _ = art.Delete([]byte(key))
}
}
}

func BenchmarkInsertART(b *testing.B) {
r := NewRadixTree[int]()
b.ResetTimer()
for n := 0; n < b.N; n++ {
uuid1, _ := uuid.GenerateUUID()
r.Insert([]byte(uuid1), n)
r, _, _ = r.Insert([]byte(uuid1), n)
}
}

Expand All @@ -1182,7 +1205,7 @@ func BenchmarkSearchART(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
uuid1, _ := uuid.GenerateUUID()
r.Insert([]byte(uuid1), n)
r, _, _ = r.Insert([]byte(uuid1), n)
r.Get([]byte(uuid1))
}
}
Expand All @@ -1192,7 +1215,7 @@ func BenchmarkDeleteART(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
uuid1, _ := uuid.GenerateUUID()
r.Insert([]byte(uuid1), n)
r.Delete([]byte(uuid1))
r, _, _ = r.Insert([]byte(uuid1), n)
r, _, _ = r.Delete([]byte(uuid1))
}
}
3 changes: 2 additions & 1 deletion txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (t *Txn[T]) recursiveInsert(node Node[T], key []byte, value T, depth int, o
depth += int(node.getPartialLen())
child, idx := t.findChild(node, key[depth])
if child != nil {
newChild, val := t.recursiveInsert(child, key, value, depth+1, old)
newChildChClone := t.writeNode(child)
newChild, val := t.recursiveInsert(newChildChClone, key, value, depth+1, old)
node.setChild(idx, newChild)
if t.trackMutate {
t.trackChannel(node.getMutateCh())
Expand Down

0 comments on commit 643e521

Please sign in to comment.