Skip to content

perf(ringqueue): compact RemoveExpired in place for zero allocation - #89

Merged
Yiming1997 merged 3 commits into
Yiming1997:mainfrom
Lawl191:perf/ringqueue-remove-expired
Aug 29, 2026
Merged

perf(ringqueue): compact RemoveExpired in place for zero allocation#89
Yiming1997 merged 3 commits into
Yiming1997:mainfrom
Lawl191:perf/ringqueue-remove-expired

Conversation

@Lawl191

@Lawl191 Lawl191 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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):

  • Before: 8192 B/op
    , 1 allocs/op
  • After: 0 B/op, 0 allocs/op

All existing tests pass, FIFO order is preserved.

将 RemoveExpired 改为原地压缩,消除每次清理的临时内存分配
(1 allocs/op → 0 allocs/op),FIFO 顺序保持不变,全部测试通过。

@Yiming1997

Copy link
Copy Markdown
Owner

@Lawl191 先按照要求修改你上一个pr

@Lawl191

Lawl191 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

已按要求将基准测试合并到功能原有的测试位置idle_ring_queue_test.go,请 review,谢谢。

@Yiming1997

Copy link
Copy Markdown
Owner

@Lawl191 上一个分支已合并,你重新拉rebase主分支到你这个分支

@Lawl191
Lawl191 force-pushed the perf/ringqueue-remove-expired branch from 74b4cd3 to 2ee795b Compare August 20, 2026 03:47
@Yiming1997

Copy link
Copy Markdown
Owner

@Lawl191 ring_queue的benchmark可以保留,但是要放在benchmark目录下。
在提新pr之前,要确保你的分支是基于最新main。
你需要rebase最新的main到你这个分支上

@Lawl191

Lawl191 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@Yiming1997 我写的 benchmark 依赖内部符号(newRingQueue / worker),但 benchmark 目录是外部测试包(package benchmark_test),移过去会编译失败;idle_ring_queue_test.go 是当前唯一能编译的内部测试位置。
请问您希望:① benchmark 保留在原位置;② 移除 benchmark?您看怎么处理合适,谢谢!
另外,分支已 rebase 到最新 main(ad4e90b),CI 已通过。

@Lawl191

Lawl191 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

明白要求了。我参照 benchmark/ 目录下已有测试的风格,用公开 API 重新实现了这个 benchmark(BenchmarkRingQueueRemoveExpired),并放到了 benchmark/ 目录下,测试文件里的旧版本已删除。麻烦再 review 一下,谢谢。

@Yiming1997

Copy link
Copy Markdown
Owner

明白要求了。我参照 benchmark/ 目录下已有测试的风格,用公开 API 重新实现了这个 benchmark(BenchmarkRingQueueRemoveExpired),并放到了 benchmark/ 目录下,测试文件里的旧版本已删除。麻烦再 review 一下,谢谢。

ok,这周找时间review

@Yiming1997
Yiming1997 merged commit 04dd1e0 into Yiming1997:main Aug 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants