Skip to content

Commit

Permalink
fix: fix listpack rpop perf
Browse files Browse the repository at this point in the history
  • Loading branch information
xgzlucario committed Nov 18, 2024
1 parent 332a07b commit faca451
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ coverage.*
redis
rotom
bench/
*.rdb
*.rdb
output/
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/arch v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
github.com/zyedidia/generic v1.2.1 h1:Zv5KS/N2m0XZZiuLS82qheRG4X1o5gsWreGb0hR7XDc=
github.com/zyedidia/generic v1.2.1/go.mod h1:ly2RBz4mnz1yeuVbQA/VFwGjK3mnHGRj1JuoG336Bis=
golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg=
Expand Down
9 changes: 3 additions & 6 deletions internal/list/listpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ func (lp *ListPack) LPop() (val string, ok bool) {

func (lp *ListPack) RPop() (val string, ok bool) {
if lp.Size() == 0 {
return "", false
return
}
it := lp.Iterator().SeekLast()
before := it.index
val, ok = string(it.Prev()), true
it.data = slices.Delete(it.data, it.index, before)
it.size--
return
it.Prev()
return it.RemoveNext(), true
}

type LpIterator struct {
Expand Down
6 changes: 2 additions & 4 deletions internal/zset/zipset.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ func (zs *ZipZSet) Remove(key string) bool {

func (zs *ZipZSet) rank(key string) (*list.LpIterator, int, float64) {
it := zs.data.Iterator().SeekLast()
index := -1
for !it.IsFirst() {
for i := 0; !it.IsFirst(); i++ {
prevKey, prevScore := zs.decode(it.Prev())
index++
if key == prevKey {
return it, index, prevScore
return it, i, prevScore
}
}
return nil, -1, 0
Expand Down
9 changes: 0 additions & 9 deletions output/bench.csv

This file was deleted.

0 comments on commit faca451

Please sign in to comment.