Skip to content

refactor: extract modes and move logic into feature folders - #43

Merged
Code0987 merged 22 commits into
mainfrom
feat/feature-folders
Sep 4, 2026
Merged

refactor: extract modes and move logic into feature folders#43
Code0987 merged 22 commits into
mainfrom
feat/feature-folders

Conversation

@Code0987

@Code0987 Code0987 commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

Same-contract layout cleanup, no API / proto / fan-out / dirty-cache change.

  1. Mode extracts — store methods out of memory.go; engine split into public / apply / cluster files (HLL, Bitmap, Counter, List, Hash, JSON, Bloom, Set, ZSet, Geo).
  2. Feature folders — owner write, snapshot/GetOrLoad, and mode tests move under pkg/<mode>/eng (and pkg/list for the former listx codec). Engine keeps thin public verbs plus a shared modeHost. Callers still use engine.Engine.LPush etc.

Design: docs/design/2026-09-02-feature-folders.md.

Release

  • This PR should not cut a release
  • Release via commit front matter (--- / release: vX.Y.Z / ---)
  • Release via PR title containing [release: vX.Y.Z]
  • Target version: v..__

Test plan

  • go test ./... locally
  • Local StoreGetHit / EngineGetHit allocs/op stayed 2 / 15
  • CI test + bench green; read <!-- supercache-bench-comment -->

Notes for reviewers

pkg/hashx / pkg/jsonx / pkg/hllx / pkg/bitmapx / pkg/cmsx / pkg/topkx keep the x names (stdlib clashes). Memory methods stay in pkg/store because of unexported dirty-cache fields. Import cycle avoided with pkg/<mode>/eng so store can still import the codec package.

Merge only if every shared smoke/micro cell is within ±10% and Get-hit allocs are flat.

Move store HLL off memory.go and split engine HLL into public API,
owner apply, and cluster hops (same layout as TopK/CMS). Unexport
hllx.merge — install is LWW replace. No contract change.
Move store Bitmap off memory.go and split engine Bitmap into public
API, owner apply, and cluster hops. No contract change.
Move store Counter off memory.go and split engine Counter into public
API, owner write, and GetOrLoad. Peer CounterIncr unchanged.
Move Geo store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty gCache and FlagGeoAdd/FlagGeoRem item fan-out.
Move ZSet store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty zCache and FlagZSetAdd/FlagZSetRem item fan-out.
Move Set store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty setCache and FlagSetAdd/FlagSetRemove item fan-out.
PeekVersion stays in memory.go.
Move Bloom store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including FlagBloomAdd item-hint fan-out and no install on GetOrLoad.
Move JSON store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty jCache and FlagJSONSet/FlagJSONDel inbox then FlagJSON snapshot.
Move Hash store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty hCache and FlagHashSet/FlagHashDel item fan-out.
Move List store methods out of memory.go and split the engine file into
public verbs, owner write/apply, and cluster forward. Same contract,
including dirty lCache and FlagList snapshot fan-out.
After stacking the mode extracts, memory.go no longer references bloom
or jsonx. errOwnerNoAddress is declared once so the engine package
builds with every extract merged.
Engine keeps thin public verbs and a shared modeHost. Owner write,
snapshot/GetOrLoad, and mode tests live under pkg/<mode>/eng and the
feature package. listx becomes pkg/list. Same Engine/Store API.
@github-actions

github-actions Bot commented Sep 4, 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: 0acc165 (2026-09-04T06:56:26Z) → this run: 0acc165 (2026-09-04T06:55:10Z)

scbench smoke

cell ops/s (main → PR) Δ ops/s p50 p99
get/hit n=1 c=1 uniform 8978 → 9051 +0.8% 111µs → 111µs 188µs → 192µs
get/hit n=1 c=10 uniform 33771 → 34635 +2.6% 268µs → 264µs 820µs → 775µs
get/hit n=3 c=10 uniform 39461 → 38832 -1.6% 223µs → 227µs 879µs → 904µs
miss/miss-cacheonly n=1 c=1 uniform 8664 → 8764 +1.2% 114µs → 113µs 233µs → 206µs
miss/miss-cacheonly n=1 c=10 uniform 36254 → 34243 -5.5% 253µs → 266µs 767µs → 832µs
set/put n=1 c=1 uniform 8695 → 8684 -0.1% 113µs → 112µs 201µs → 239µs
set/put n=1 c=10 uniform 33314 → 33674 +1.1% 274µs → 271µs 815µs → 811µs

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

go test -bench (ns/op)

benchmark ns/op (main → PR) Δ allocs/op
BenchmarkEngineDelete 762 → 758 -0.5% 6 → 6
BenchmarkEngineGetHit 1198 → 1162 -3.0% 15 → 15
BenchmarkEngineGetHitParallel 1229 → 1235 +0.5% 15 → 15
BenchmarkEngineGetMissCacheOnly 888 → 867 -2.3% 14 → 14
BenchmarkEngineGetMissCacheOnlyParallel 680 → 649 -4.6% 14 → 14
BenchmarkEngineGetMissLoadThrough 1859 → 1610 -13.4% 24 → 24
BenchmarkEngineGetMissLoadThroughParallel 2134 → 1856 -13.0% 23 → 23
BenchmarkEnginePut 1601 → 1535 -4.1% 18 → 18
BenchmarkEnginePutParallel 1438 → 1356 -5.7% 18 → 18
BenchmarkStoreBitSet 112 → 113 +0.6% 1 → 1
BenchmarkStoreCGetHit 74 → 73 -2.1% 0 → 0
BenchmarkStoreCIncr 101 → 100 -1.0% 1 → 1
BenchmarkStoreCMSIncr 121 → 120 -0.7% 0 → 0
BenchmarkStoreCMSIncrN 125 → 121 -3.2% 0 → 0
BenchmarkStoreGeoAdd 9548 → 9225 -3.4% 2 → 2
BenchmarkStoreGeoPosHit 88 → 89 +0.8% 0 → 0
BenchmarkStoreGeoPosMiss 87 → 87 +0.6% 0 → 0
BenchmarkStoreGetHit 300 → 317 +5.8% 2 → 2
BenchmarkStoreGetHitParallel 363 → 376 +3.6% 2 → 2
BenchmarkStoreHGetHit 92 → 91 -0.7% 1 → 1
BenchmarkStoreHGetMiss 85 → 85 +0.1% 0 → 0
BenchmarkStoreHLLAdd 99 → 100 +0.3% 0 → 0
BenchmarkStoreHSet 10592 → 10586 -0.1% 3 → 3
BenchmarkStoreJsonSet 26345 → 26512 +0.6% 207 → 207
BenchmarkStorePut 302 → 301 -0.4% 2 → 2
BenchmarkStorePutParallel 351 → 360 +2.7% 2 → 2
BenchmarkStoreSetAdd 9214 → 9691 +5.2% 2 → 2
BenchmarkStoreSetContainsHit 87 → 88 +0.9% 0 → 0
BenchmarkStoreSetContainsMiss 84 → 84 -0.2% 0 → 0
BenchmarkStoreTopKAdd 988 → 1006 +1.8% 20 → 20
BenchmarkStoreZAdd 9562 → 9601 +0.4% 2 → 2
BenchmarkStoreZScoreHit 86 → 87 +1.6% 0 → 0
BenchmarkStoreZScoreMiss 87 → 86 -0.5% 0 → 0

Posted by CI bench job. Not a merge gate.

Go LIFO defers closed FanoutPool while warmup workers still
called Submit. CI -race failed on TestJoinHandoffAvoidsDataSourceReload.
Test-only teardown order; production Submit/Close left unchanged.
@Code0987
Code0987 merged commit 40b520e into main Sep 4, 2026
2 checks passed
@Code0987
Code0987 deleted the feat/feature-folders branch September 4, 2026 06:59
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