Skip to content

Commit 2b650e1

Browse files
committed
refactor(core)!: decompose hypercache.go into domain modules and modernize ConcurrentMap iterator
Split the monolithic hypercache.go (~950 lines removed) into focused files: - hypercache_construct.go: backend resolution and base construction - hypercache_io.go: Set/Get/GetOrSet/GetMultiple/Remove/Clear/List - hypercache_eviction.go: eviction configuration, loop, and triggers - hypercache_expiration.go: expiration routine and trigger logic - hypercache_dist.go: distributed metrics helpers (DistMetrics, ClusterOwners, etc.) Replace ConcurrentMap's channel-based IterBuffered() with iter.Seq2-based All(), eliminating fan-in goroutines and per-shard channel allocations. Update all callers in dist_memory, dist_http_server, and inmemory backends. Upgrade hash function from inlined FNV-1a to xxhash64 (XOR-folded to 32 bits) for better avalanche and ~1-3% speedup on longer keys. Add bench-step3.txt with benchmark results on Apple M4 Pro. BREAKING CHANGE: IterBuffered() and Tuple type removed from ConcurrentMap; use All() iter.Seq2[string, *Item] instead.
1 parent b8732c5 commit 2b650e1

14 files changed

Lines changed: 1164 additions & 1054 deletions

bench-step3.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
goos: darwin
2+
goarch: arm64
3+
pkg: github.com/hyp3rd/hypercache/pkg/cache/v2
4+
cpu: Apple M4 Pro
5+
BenchmarkConcurrentMap_Count-14 122877582 9.726 ns/op 0 B/op 0 allocs/op
6+
BenchmarkConcurrentMap_Count-14 122084272 9.828 ns/op 0 B/op 0 allocs/op
7+
BenchmarkConcurrentMap_Count-14 123835690 9.683 ns/op 0 B/op 0 allocs/op
8+
BenchmarkConcurrentMap_Count-14 122782857 9.763 ns/op 0 B/op 0 allocs/op
9+
BenchmarkConcurrentMap_Count-14 124295282 9.649 ns/op 0 B/op 0 allocs/op
10+
BenchmarkConcurrentMap_CountParallel-14 79226004 13.44 ns/op 9 B/op 0 allocs/op
11+
BenchmarkConcurrentMap_CountParallel-14 82377501 13.32 ns/op 9 B/op 0 allocs/op
12+
BenchmarkConcurrentMap_CountParallel-14 93374600 12.83 ns/op 9 B/op 0 allocs/op
13+
BenchmarkConcurrentMap_CountParallel-14 74157042 14.11 ns/op 9 B/op 0 allocs/op
14+
BenchmarkConcurrentMap_CountParallel-14 89445556 13.49 ns/op 8 B/op 0 allocs/op
15+
BenchmarkConcurrentMap_GetShard-14 100000000 10.08 ns/op 0 B/op 0 allocs/op
16+
BenchmarkConcurrentMap_GetShard-14 120268629 10.01 ns/op 0 B/op 0 allocs/op
17+
BenchmarkConcurrentMap_GetShard-14 100000000 10.22 ns/op 0 B/op 0 allocs/op
18+
BenchmarkConcurrentMap_GetShard-14 100000000 10.03 ns/op 0 B/op 0 allocs/op
19+
BenchmarkConcurrentMap_GetShard-14 100000000 10.07 ns/op 0 B/op 0 allocs/op
20+
BenchmarkConcurrentMap_All-14 46454 26087 ns/op 0 B/op 0 allocs/op
21+
BenchmarkConcurrentMap_All-14 44976 26633 ns/op 0 B/op 0 allocs/op
22+
BenchmarkConcurrentMap_All-14 45357 26457 ns/op 0 B/op 0 allocs/op
23+
BenchmarkConcurrentMap_All-14 41589 27827 ns/op 0 B/op 0 allocs/op
24+
BenchmarkConcurrentMap_All-14 45512 26454 ns/op 0 B/op 0 allocs/op
25+
PASS
26+
ok github.com/hyp3rd/hypercache/pkg/cache/v2 23.302s

0 commit comments

Comments
 (0)