Commit b458967
authored
perf(linked): recycle nodes via internal free list + refresh README benchmarks (#58)
* perf(linked): recycle popped nodes via internal free list
Offer allocated a fresh *node[T] every call and Get handed popped
nodes to the GC. In the steady-state offer/get pattern that's one
allocation per cycle — visible in the benchmark as 16 B/op / 1 alloc.
Maintain an internal free stack of popped nodes (capped at 64 to avoid
retaining memory after a large drain). Offer pulls from it first,
Get pushes onto it. No cross-goroutine pool contention because the
list lives under the queue's existing lock.
Benchmark on darwin/arm64, M4 Pro:
before BenchmarkLinkedQueue/Get_Offer-12 19.70 ns/op 16 B/op 1 allocs/op
after BenchmarkLinkedQueue/Get_Offer-12 14.75 ns/op 0 B/op 0 allocs/op
before BenchmarkLinkedQueue/Offer-12 21.71 ns/op 16 B/op 1 allocs/op
after BenchmarkLinkedQueue/Offer-12 22.42 ns/op 16 B/op 1 allocs/op
Offer-only pattern keeps the same alloc profile (free list stays
empty). Peek unchanged. Get no longer issues an allocation in the
common case.
Refs #47
* docs(readme): refresh benchmarks post-fixes
Numbers taken on an Apple M4 Pro (darwin/arm64), go test -bench=. -count=3.
The old table was from October 2023 on an 8-core machine and predates
all the recent fixes (pointer-retention, Broadcast-vs-Signal, heap.Pop
correction, and the linked queue's node free list).
Most notable change: LinkedQueue/Get_Offer drops from 16 B / 1 alloc
to 0 B / 0 allocs.
* docs(readme): drop hardware details from benchmark block
* docs(readme): drop MarshalJSON from benchmark table
* test(linked): cover free-list reuse and cap-reached branches
The node free list added in this branch introduced two new branches
that the existing tests didn't hit — "Offer after Get reuses a
recycled node" and "drain past freeCap stops growing the free list".
Coverage fell to 98.4% and the 100% gate failed.
Add a dedicated sub-test that exercises both paths. No observable
behaviour change.
* test(linked): split recycle coverage test to keep gocognit under 201 parent b7d73c6 commit b458967
3 files changed
Lines changed: 118 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
287 | 287 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
52 | 60 | | |
53 | 61 | | |
54 | 62 | | |
55 | | - | |
56 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
76 | | - | |
| 88 | + | |
| 89 | + | |
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
| |||
87 | 100 | | |
88 | 101 | | |
89 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
90 | 132 | | |
91 | 133 | | |
92 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
25 | 85 | | |
26 | 86 | | |
27 | 87 | | |
| |||
0 commit comments