Repository navigation
Size ghost history from resident counts - #140
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 21, 2026 23:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
unsync::Cache::withandunsync::Cache::with_weighter. Both now take weight capacity first.OptionsBuilderaccepts weight capacity alone. The sync cache usesestimated_items_capacityto 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 usesweight_capacityas 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_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 mostadditionalextra ghost slots using the larger of the last sample and the limit projected fromlen() + 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
statsand without default features.