Skip to content

Speed up cold cache digest computation - #2771

Merged
joelhawksley merged 1 commit into
mainfrom
joelhawksley-benchmark-optimizations
Nov 3, 2026
Merged

joelhawksley merged 1 commit into
mainfrom
joelhawksley-benchmark-optimizations

Conversation

@joelhawksley

Copy link
Copy Markdown
Member

What are you trying to accomplish?

Reduce repeated filesystem work during cold cache digest computation.

Measurement Before After
Cold digest 97.6 ms 16.4 ms
Cold digest / partial digest ratio 192.819 31.670
ViewComponent boot work 654 ms 645 ms

Three paired runs, 15 passes per run, Ruby 4.0.7 / Rails 8.1.4. The cold-digest ratio improves 83.6%; rendering ratios stay within about 1%. The small boot difference is within noise.

What approach did you choose and why?

Reuse the existing boot-time directory and source-file caches while building a digest tree. Make nested cache scopes preserve the outer cache, and memoize Ruby-file discovery and file hashes within one digest computation. Nothing persists across computations or reloads.

Anything you want to highlight for special attention from reviewers?

Cold-digest allocations increase from 69,544 to 77,783 (about 12%) in exchange for fewer filesystem operations. Regression coverage checks nested cache cleanup, shared scans and hashes, unchanged digest values, and invalidation.

Benchmark reproduction

Uses the unchanged performance/measure.rb and performance/compare.rb scripts on this branch, with a separate checkout of the base revision:

for round in 1 2 3; do
  VIEW_COMPONENT_LIB=/path/to/base/lib bundle exec ruby performance/measure.rb "tmp/performance/base/$round.json"
  bundle exec ruby performance/measure.rb "tmp/performance/head/$round.json"
done
bundle exec ruby performance/compare.rb tmp/performance/base tmp/performance/head

The comparison pools individual scenario/reference ratios across processes; the absolute times above are medians of the three run medians.

@joelhawksley
joelhawksley merged commit 5e1e82a into main Nov 3, 2026
30 checks passed
@joelhawksley
joelhawksley deleted the joelhawksley-benchmark-optimizations branch November 3, 2026 18:25
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