Skip to content

Size ghost history from resident counts - #140

Merged
arthurprs merged 7 commits into
masterfrom
feat/len-based-ghost-sizing
Nov 21, 2026
Merged

arthurprs merged 7 commits into
masterfrom
feat/len-based-ghost-sizing

Conversation

@arthurprs

@arthurprs arthurprs commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

The number of entries a weighted cache can hold changes with the weight mix. Each shard now sizes its ghost history from the resident count it observes. Ghost entries store only key hashes.

Upgrading

  • Drop the leading item estimate from unsync::Cache::with and unsync::Cache::with_weighter. Both now take weight capacity first.
  • OptionsBuilder accepts weight capacity alone. The sync cache uses estimated_items_capacity to avoid creating more shards than its estimated item count can support. It halves the shard count until it estimates at least 32 items per shard or reaches one shard. If you omit the estimate, it uses weight_capacity as the estimated item count for this calculation. Supply an item estimate or use fewer shards if heavy entries exceed a shard’s admission limit.
  • Ghost history can grow or shrink under the same configuration. If a zero item estimate previously disabled history, set ghost_allocation(0.0).

Sizing and reserve

The ghost limit is floor(len() * ghost_allocation), sampled on the first ghost addition, every 255 additions thereafter, and when capacity changes. reserve(additional) budgets at most additional extra ghost slots using the larger of the last sample and the limit projected from len() + additional. At zero weight capacity it reserves the requested item slots.

Validation

The default suite passed 85 tests with one ignored doctest. The library tests also passed with stats and without default features.

Use the weight budget for shard sizing when the builder has no item
estimate. Sample resident counts periodically to size ghost history.
Check for empty history after trimming the resized limit. Document
how weight-only sizing can affect admission in a sharded cache.
@arthurprs arthurprs changed the title Estimate ghost capacity when the item estimate is omitted Size ghost history from resident counts Nov 21, 2026
@arthurprs arthurprs changed the title Size ghost history from resident counts Size ghost history from resident counts automatically Nov 21, 2026
@arthurprs
arthurprs marked this pull request as ready for review November 21, 2026 23:01
@arthurprs arthurprs changed the title Size ghost history from resident counts automatically Size ghost history from resident counts Nov 21, 2026
@arthurprs
arthurprs merged commit 5799f7c into master Nov 21, 2026
12 checks passed
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