perf(ringqueue): compact RemoveExpired in place for zero allocation - #89
Conversation
|
@Lawl191 先按照要求修改你上一个pr |
|
已按要求将基准测试合并到功能原有的测试位置idle_ring_queue_test.go,请 review,谢谢。 |
|
@Lawl191 上一个分支已合并,你重新拉rebase主分支到你这个分支 |
74b4cd3 to
2ee795b
Compare
|
@Lawl191 ring_queue的benchmark可以保留,但是要放在benchmark目录下。 |
|
@Yiming1997 我写的 benchmark 依赖内部符号(newRingQueue / worker),但 benchmark 目录是外部测试包(package benchmark_test),移过去会编译失败;idle_ring_queue_test.go 是当前唯一能编译的内部测试位置。 |
|
明白要求了。我参照 benchmark/ 目录下已有测试的风格,用公开 API 重新实现了这个 benchmark(BenchmarkRingQueueRemoveExpired),并放到了 benchmark/ 目录下,测试文件里的旧版本已删除。麻烦再 review 一下,谢谢。 |
ok,这周找时间review |
RemoveExpired previously allocated a temporary slice to collect
survivors before compacting them back, causing 1 alloc (8192 B) per
cleanup cycle.
This change compacts survivors in place: the write position never
passes the scan position, so the write target has always been read
already. This removes the temporary allocation entirely.
Benchmark (1000 idle workers, half expired):
, 1 allocs/op
All existing tests pass, FIFO order is preserved.
将 RemoveExpired 改为原地压缩,消除每次清理的临时内存分配
(1 allocs/op → 0 allocs/op),FIFO 顺序保持不变,全部测试通过。