bytedance / gopkg

Universal Utilities for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用zset(skiplist)时,发现其remove,incr, updateScore比想象中的慢非常多

chgz opened this issue · comments

Operating System

Windows 10

Go Version

1.21

Package Version

latest

Affected Packages

collection/zset

Expected Behavior

使用zset(skiplist)时,发现其remove,incr, updateScore比想象中的慢非常多。
初步看了下cpu开销,发现lessthan的比较函数执行次数远高于 incr, zrem的复杂度M*log(N)的次数量级。
比如添加1w个元素耗时lessthan执行次数:221038,更新这1w个元素要lessthan执行次数: 98797380
把测试数据增加到10w个,lessthan次数到:2748187, 等了很久都没等到10w个元素更新完成(手动停止了)

Actual Behavior

Reproduction Steps

创建一个zset,

  1. 添加10000个元素
  2. incr 10000个元素
  3. 删除这10000个元素

Other Information

No response

测试的分值,是0-10000的随机值