Sort cache entries only when choosing eviction order - #857
Open
OskarEichler wants to merge 1 commit into
Open
Conversation
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
Initial file cache size calculation does not sort entries; eviction still sorts by modification time before choosing files to remove.
Reproduction and evidence
Move modification-time sorting from file enumeration to the eviction path. Computing a sum of file sizes does not need sorted entries; eviction still sorts the same file/stat pairs with the same key before choosing files.
Measured first-size computation on real local cache directories (Ruby 4.0.6, three fresh stores per sample, 16 samples per variant in alternating process order):
This removes roughly 20% of measured initial-size allocations for larger directories. Timing is local and modest/mixed, not a general application-throughput claim. Subsequent cached size reads are unaffected. Empty/single/multiple-entry stores and identical eviction choices (including equal mtimes) were checked.
Ruby examples use
require "sprockets"; require "tmpdir".Verification
Compatibility and limitations
Breaking changes: none intended. Initial enumeration no longer sorts internally; public cache semantics and eviction ordering are unchanged. No new dependencies or version upgrades. Based on installed release/current main
49d9f20c00ac7d9a7ee57db058961edcccd86699.Upstream-only contribution: no application fork pin, deployment or current-master boot claim. No checked-in tests were added or modified under the requesting repository's no-test-edit policy; focused evidence ran externally. Older Ruby/Linux/JRuby verification is left to upstream CI, not claimed locally. Prepared with AI assistance. This is a focused change, not an exhaustive review.