mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
## Summary Two improvements to BM25 stats memory accounting in idfOracle: ### 1. Per-entry estimate: 80 → 20 bytes/entry The previous hardcoded `bm25StatsPerEntryBytes = 80` overestimates `map[uint32]int32` memory by 4-7x. Empirical measurement on Go 1.24 (median of 5 runs, n ≥ 10K to avoid GC noise): | n | heap delta | bytes/entry | overestimate vs 80 | |---|---|---|---| | 10K | 152 KB | 15.22 | 5.2× | | 100K | 1.22 MB | 12.18 | 6.6× | | 1M | 19.4 MB | 19.43 | 4.1× | | 5M | 77.9 MB | 15.58 | 5.1× | | 10M | 156 MB | 15.58 | 5.1× | | 50M | 623 MB | 12.47 | 6.4× | Steady-state cost oscillates between **12 and 19.5 bytes/entry** depending on the swiss table fill ratio (peak ~19.5 right after a 2× capacity grow, trough ~12 when near load factor 7/8). Root cause: the original comment claimed "bucket overhead ~72B per entry", but Go map buckets/groups hold 8 entries each, so amortized overhead is ~10 bytes/entry, not 72. **Fix**: lower the default to 20 (covers measured upper bound 19.5 with small safety margin) and expose as `queryNode.idfOracle.bm25StatsBytesPerEntry` (refreshable) for runtime tuning. ### 2. Skip cgo Charge/Refund when tiered eviction is disabled When `queryNode.segcore.tieredStorage.evictionEnabled = false` (the default), the C++ caching layer's resource accounting is inert — no eviction will be driven by it. The per-load `C.ChargeLoadedResource` / `C.RefundLoadedResource` cgo calls are pure overhead in this case. **Fix**: gate `syncResource` and `checkMemoryResource` on the eviction flag. Skip entirely when eviction is off. ## Impact - ~75% reduction in cache budget consumed by BM25 stats (when eviction enabled) - Eliminates per-segment cgo overhead in default deployments (eviction off) - Tunable per-entry estimate without redeploying ## Test plan - [x] `TestIDFOracle` passes - [x] `TestBM25Stats_MemSize` passes with the new configurable value - [x] Verified memory measurement methodology with multiple sample sizes issue: #46468 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: aoiasd <zhicheng.yue@zilliz.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>