Skip to content

Sort cache entries only when choosing eviction order - #857

Open
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/initial-size-sort
Open

Sort cache entries only when choosing eviction order#857
OskarEichler wants to merge 1 commit into
rails:mainfrom
OskarEichler:codex/initial-size-sort

Conversation

@OskarEichler

Copy link
Copy Markdown

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):

Files Baseline allocations Fixed allocations Baseline median Fixed median
10 216 174 0.269 ms 0.260 ms
1,000 15,066 12,054 10.140 ms 10.169 ms
10,000 150,066 120,054 106.520 ms 102.422 ms

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

  • Isolated patch: unchanged full and isolated test tasks each pass 913 tests /4,109 assertions /zero failures/errors /four skips, Ruby 3.2.11 and 4.0.6.
  • 16 focused external checks pass on each Ruby. The overwrite defect reproduces on the release baseline; sorting equivalence is checked against the original algorithm.
  • Full RuboCop: 133 files, zero offenses. Changed syntax passes both Rubies; whitespace checks pass. All Ruby commands use rbenv.
  • Gem build/content comparison preserves 84 paths, version 4.4.1, Ruby >=2.5 and dependency metadata. Only README, CHANGELOG and FileStore differ.

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.

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