Skip to content

refactor: extract ModeCounter files (no contract change) - #42

Closed
Code0987 wants to merge 1 commit into
mainfrom
feat/refactor-counter
Closed

Code0987 wants to merge 1 commit into
mainfrom
feat/refactor-counter

Conversation

@Code0987

@Code0987 Code0987 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Design

docs/design/2026-09-02-refactor-counter.md

Independent of #40 (HLL) and #41 (Bitmap). Same layout, Counter only.

What landed

Same Incr / CounterGet contract (peer CounterIncr still returns n).

File Role
pkg/store/counter.go store methods (out of memory.go)
pkg/engine/counter.go public verbs
pkg/engine/counter_apply.go owner write + snapshot install
pkg/engine/counter_cluster.go GetOrLoad / snapshot fan-out

Tests

go test ./pkg/counter ./pkg/store ./pkg/engine

Local bench

BenchmarkStoreGetHit 2 allocs/op, BenchmarkEngineGetHit 15 allocs/op (flat).

Bench risk

No new Get/Peek logic. Shared smoke/micro ±10%. Get-hit allocs must stay flat.

Move store Counter off memory.go and split engine Counter into public
API, owner write, and GetOrLoad. Peer CounterIncr unchanged.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

SuperCache bench vs main

Both sides ran once on this same GitHub runner (main, then this PR). Not a merge gate.

Baseline: cc4a44e (2026-09-02T13:48:42Z) → this run: cc4a44e (2026-09-02T13:47:26Z)

scbench smoke

cell ops/s (main → PR) Δ ops/s p50 p99
get/hit n=1 c=1 uniform 8883 → 8834 -0.5% 112µs → 113µs 189µs → 187µs
get/hit n=1 c=10 uniform 35650 → 35009 -1.8% 256µs → 261µs 751µs → 772µs
get/hit n=3 c=10 uniform 40409 → 40304 -0.3% 219µs → 220µs 820µs → 822µs
miss/miss-cacheonly n=1 c=1 uniform 8660 → 8647 -0.2% 114µs → 115µs 209µs → 207µs
miss/miss-cacheonly n=1 c=10 uniform 36711 → 35061 -4.5% 247µs → 257µs 778µs → 816µs
set/put n=1 c=1 uniform 8527 → 8555 +0.3% 116µs → 115µs 202µs → 197µs
set/put n=1 c=10 uniform 33824 → 33900 +0.2% 271µs → 270µs 801µs → 801µs

Δ ops/s: green-ish is higher throughput. Latency: lower is better.

go test -bench (ns/op)

benchmark ns/op (main → PR) Δ allocs/op
BenchmarkEngineBitCount 170 → 169 -0.1% 0 → 0
BenchmarkEngineBitGetHit 164 → 164 +0.1% 0 → 0
BenchmarkEngineBitGetHitParallel 210 → 192 -8.7% 0 → 0
BenchmarkEngineBitSet 505 → 507 +0.3% 2 → 2
BenchmarkEngineBitSetParallel 582 → 598 +2.8% 2 → 2
BenchmarkEngineCMSIncr 8444 → 8593 +1.8% 1 → 1
BenchmarkEngineCMSIncrN 8322 → 9377 +12.7% 1 → 1
BenchmarkEngineCMSIncrParallel 12421 → 15123 +21.8% worse 1 → 1
BenchmarkEngineCMSQueryHit 203 → 202 -0.3% 1 → 1
BenchmarkEngineCMSQueryHitParallel 250 → 248 -0.8% 1 → 1
BenchmarkEngineCounterGet 160 → 159 -0.3% 0 → 0
BenchmarkEngineCounterGetParallel 192 → 192 +0.3% 0 → 0
BenchmarkEngineDelete 822 → 810 -1.4% 6 → 6
BenchmarkEngineGeoAdd 9879 → 9912 +0.3% 8 → 8
BenchmarkEngineGeoCard 161 → 160 -0.5% 0 → 0
BenchmarkEngineGeoPosHit 101 → 101 -0.1% 0 → 0
BenchmarkEngineGeoRadius 344460 → 350679 +1.8% 1016 → 1016
BenchmarkEngineGetHit 1192 → 1199 +0.6% 15 → 15
BenchmarkEngineGetHitParallel 1242 → 1213 -2.3% 15 → 15
BenchmarkEngineGetMissCacheOnly 875 → 890 +1.7% 14 → 14
BenchmarkEngineGetMissCacheOnlyParallel 643 → 667 +3.7% 14 → 14
BenchmarkEngineGetMissLoadThrough 1646 → 1635 -0.7% 24 → 24
BenchmarkEngineGetMissLoadThroughParallel 1833 → 1820 -0.7% 23 → 23
BenchmarkEngineHGetAll 14719 → 15389 +4.6% 134 → 134
BenchmarkEngineHGetHit 109 → 112 +2.9% 1 → 1
BenchmarkEngineHGetHitParallel 138 → 128 -7.3% 1 → 1
BenchmarkEngineHGetMiss 173 → 173 +0.3% 0 → 0
BenchmarkEngineHLLAdd 2183 → 2630 +20.5% worse 1 → 1
BenchmarkEngineHLLAddParallel 2866 → 3429 +19.6% 1 → 1
BenchmarkEngineHLLCountHit 115812 → 115856 +0.0% 0 → 0
BenchmarkEngineHLLCountHitParallel 132820 → 133579 +0.6% 0 → 0
BenchmarkEngineHLen 160 → 160 +0.1% 0 → 0
BenchmarkEngineHSet 10879 → 10984 +1.0% 6 → 6
BenchmarkEngineHSetParallel 13426 → 11669 -13.1% 6 → 6
BenchmarkEngineIncr 380 → 383 +0.7% 1 → 1
BenchmarkEngineIncrParallel 421 → 428 +1.8% 1 → 1
BenchmarkEngineJsonGet 195 → 195 +0.0% 1 → 1
BenchmarkEngineJsonGetHit 413 → 431 +4.3% 5 → 5
BenchmarkEngineJsonGetHitParallel 486 → 500 +2.9% 5 → 5
BenchmarkEngineJsonSet 28422 → 29177 +2.7% 215 → 215
BenchmarkEngineJsonSetParallel 17669 → 17340 -1.9% 118 → 118
BenchmarkEngineLIndexHit 183 → 182 -0.3% 1 → 1
BenchmarkEngineLLen 159 → 159 +0.1% 0 → 0
BenchmarkEngineLPush 10158 → 11053 +8.8% 18 → 18
BenchmarkEngineLRange 448 → 461 +3.0% 11 → 11
BenchmarkEnginePut 1529 → 1522 -0.5% 18 → 18
BenchmarkEnginePutParallel 1403 → 1463 +4.3% 18 → 18
BenchmarkEngineSetAdd 9572 → 9548 -0.3% 4 → 4
BenchmarkEngineSetCard 164 → 165 +0.4% 0 → 0
BenchmarkEngineSetContainsHit 109 → 103 -5.0% 0 → 0
BenchmarkEngineSetContainsHitParallel 122 → 123 +1.1% 0 → 0
BenchmarkEngineSetContainsMiss 175 → 174 -0.3% 0 → 0
BenchmarkEngineSetMembers 5846 → 5761 -1.5% 66 → 66
BenchmarkEngineSetRemove 1104 → 1145 +3.7% 1 → 1
BenchmarkEngineTopKAdd 1458 → 1511 +3.6% 21 → 21
BenchmarkEngineTopKAddParallel 1765 → 1846 +4.6% 21 → 21
BenchmarkEngineTopKListHit 570 → 590 +3.7% 11 → 11
BenchmarkEngineTopKListHitParallel 644 → 689 +7.0% 11 → 11
BenchmarkEngineZAdd 10237 → 10279 +0.4% 8 → 8
BenchmarkEngineZCard 159 → 160 +0.6% 0 → 0
BenchmarkEngineZRange 195342 → 196486 +0.6% 1017 → 1017
BenchmarkEngineZRangeByScore 195969 → 197903 +1.0% 1021 → 1021
BenchmarkEngineZScoreHit 103 → 104 +1.1% 0 → 0
BenchmarkStoreBitSet 113 → 113 -0.4% 1 → 1
BenchmarkStoreCGetHit 73 → 73 +0.2% 0 → 0
BenchmarkStoreCIncr 101 → 100 -0.5% 1 → 1
BenchmarkStoreCMSIncr 121 → 121 +0.0% 0 → 0
BenchmarkStoreCMSIncrN 123 → 121 -1.2% 0 → 0
BenchmarkStoreGeoAdd 9598 → 9582 -0.2% 2 → 2
BenchmarkStoreGeoPosHit 88 → 91 +2.9% 0 → 0
BenchmarkStoreGeoPosMiss 87 → 87 +0.0% 0 → 0
BenchmarkStoreGetHit 290 → 296 +1.9% 2 → 2
BenchmarkStoreGetHitParallel 334 → 336 +0.5% 2 → 2
BenchmarkStoreHGetHit 92 → 97 +5.3% 1 → 1
BenchmarkStoreHGetMiss 85 → 85 +0.2% 0 → 0
BenchmarkStoreHLLAdd 100 → 100 +0.6% 0 → 0
BenchmarkStoreHSet 10576 → 10619 +0.4% 3 → 3
BenchmarkStoreJsonSet 26312 → 26327 +0.1% 207 → 207
BenchmarkStorePut 301 → 300 -0.4% 2 → 2
BenchmarkStorePutParallel 361 → 354 -2.1% 2 → 2
BenchmarkStoreSetAdd 9212 → 9233 +0.2% 2 → 2
BenchmarkStoreSetContainsHit 89 → 90 +1.0% 0 → 0
BenchmarkStoreSetContainsMiss 85 → 84 -0.8% 0 → 0
BenchmarkStoreTopKAdd 980 → 985 +0.5% 20 → 20
BenchmarkStoreZAdd 9540 → 9556 +0.2% 2 → 2
BenchmarkStoreZScoreHit 86 → 86 +0.5% 0 → 0
BenchmarkStoreZScoreMiss 88 → 86 -2.6% 0 → 0

Posted by CI bench job. Not a merge gate.

@Code0987

Code0987 commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Closing — you asked to review locally, not commit/PR.

@Code0987 Code0987 closed this Sep 2, 2026
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.

1 participant