-
Notifications
You must be signed in to change notification settings - Fork 424
Open
Description
- btree.go line 152 should be index < len(*s) - 1, because otherwise the "if" is always true,
and the minor optimization of not calling a copy that is going to do nothing anyway (as [index+1:] gives an empty slice when index==len(*s)-1 so copy into an empty slice does nothing anyway) is missed... right? (edit: or omit the if? profiling might show the cpu is happier with straight-line rather than branching code...)
func (s *items) insertAt(index int, item Item) {
*s = append(*s, nil)
if index < len(*s) { // line 152
copy((*s)[index+1:], (*s)[index:])
}
(*s)[index] = item
}
- On sequential reads (a "full table scan") this b-tree kicks some serious butt.
It is sooo fast. And inserts are fantastically fast too. I mean, a full in-order read so
much faster than the built-in go map it is like 2x ridiculous--probably due to way fewer
cache misses. But the thing is, deletes are suuuper slow in comparison. Do you
have any intuition as to why deletes from the btree are so slow? Could tombstoning help?
I saw the comments on Clear but I want to support arbitrary delete patterns
and not have them be so very different from insert.
Comparison to built in Go map:
map time to store 10_000_000 keys: 2.466118634s (246ns/op)
map reads 10_000_000 keys: elapsed 101.076718ms (10ns/op)
map deletes 10000000 keys: elapsed 1.36421433s (136ns/op)
// degree 30 b-tree github.com/google/btree (and 3000 even faster)
google/btree time to store 10_000_000 keys: 1.835054285s (183ns/op)
google/btree reads 10_000_000 keys: elapsed 52.309863ms (5ns/op)
// (deletes are very slow though! like an order of magnitude slower...)
google/btree delete 10_000_000 keys: elapsed 13.386230659s (1.338µs/op)
Metadata
Metadata
Assignees
Labels
No labels