Extract weighted partitioning into WeightedLfuCapacityPartition#815
Draft
bitfaster wants to merge 1 commit into
Draft
Extract weighted partitioning into WeightedLfuCapacityPartition#815bitfaster wants to merge 1 commit into
bitfaster wants to merge 1 commit into
Conversation
Move the weighted hill-climb (OptimizeWeightedPartitioning + Determine/Increase/Decrease/CopySign), the window/main weighted maximums, the climb state, and all weighted tuning consts out of ConcurrentLfuCore into a new WeightedLfuCapacityPartition, mirroring LfuCapacityPartition. Both implement a new internal ICapacityPartition. The climb reaches back into the core via a generic OptimizePartitioning(ref core, ...) method, matching the existing INodePolicy.ExpireEntries(ref core) pattern; weighted sizes remain in the core as accounting. Behavior-preserving: full suite green (1579). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Refactor (no behavior change): extract the weighted partitioning logic out of the large
ConcurrentLfuCoreinto a dedicatedWeightedLfuCapacityPartition, mirroringLfuCapacityPartition.What moves
internal interface ICapacityPartition { int Capacity { get; } }(Lfu namespace; distinctfrom the existing public
Lru.ICapacityPartition). BothLfuCapacityPartitionand the newWeightedLfuCapacityPartitionimplement it.WeightedLfuCapacityPartitionholds the window/main weighted maximums(
Maximum/WindowMaximum/MainProtectedMaximum), the hill-climb state, all weighted tuningconsts (
MainPercentage,MainProtectedPercentage,AdmitHashDosThreshold, theHillClimber*set,
SmallCacheThreshold,QueueTransferThreshold), the maximum-initialization, and the climb(
OptimizePartitioning+DetermineWeightedAdjustment/IncreaseWindow/DecreaseWindow/CopySign).ConcurrentLfuCorenow holds anICapacityPartitionand is ~150 lines lighter.Design
The weighted climb physically moves nodes between the core's LRU lists and mutates the core's
weighted sizes, so it isn't a pure calculator like
LfuCapacityPartition. The partition'sOptimizePartitioning<K,V,N,P,E>(ref ConcurrentLfuCore<…> cache, ICacheMetrics metrics, int sampleThreshold)reaches back into the core — the same pattern as the existingINodePolicy.ExpireEntries(ref ConcurrentLfuCore<…> cache). Conceptual boundary: the maximumsmove to the partition; the sizes (
weightedSize/windowWeightedSize/mainProtectedWeightedSize)remain in the core as runtime accounting (the climb mutates them via the
ref). The core exposes theminimum needed members as
internalfor the reach-back; the count and weighted paths select theconcrete partition via the compile-time
IsWeightedflag (cast helpersCountCapacity/WeightedCapacity).Testing
TFMs (netstandard2.0, netcoreapp3.1, net6.0, net10.0, net48);
dotnet formatclean.WeightedLfuCapacityPartitionTestscovers the ctor maximum split (mirrorsLfuCapacityPartitionTests); the climb itself is exercised end-to-end by the existingWeightedNodePolicyTestswindow-adaptation test.Notes / possible follow-ups
internalsurface slightly (lists, two size fields,ReFitProtectedWeighted). A narrower set of encapsulated move helpers is a possible follow-up.AdmitHashDosThresholdis admission tuning (used byAdmitCandidateWeighted) rather thanpartitioning, but moves with the other tuning consts per the requested grouping.
Draft
Opened as a draft for review of the boundary and the
ICapacityPartitionshape.