Skip to content

Conversation

@mbovel
Copy link
Member

@mbovel mbovel commented Dec 19, 2025

The main goal of this PR is to enable caching of file contents across compiler runs. Importantly, this PR is careful not to change any of the existing caching strategies (except for compilation tests). It only enables users of the compiler to customize them.

This PR follows a series of experiments (#24630, #24644, #24737, #24777) in which I tried caching at different levels.

This PR addresses the problem by introducing two new concepts:

  • CacheStore: a configurable set of caches that can potentially be shared across runs. A CacheStore is associated with each context.
  • Cache: the interface for individual caches, together with a collection of composable implementations: thread-safe and thread-unsafe variants; a file-based implementation that invalidates entries when files on disk change (refactored from the existing FileBasedCache); and a filter cache that allows caching only a subset of keys.

This PR deliberately sidesteps the question of how these caches should be used by other tools, such as Zinc. Addressing that will require further work on API boundaries. However, the proposed changes are self-contained and already allow speeding up compilation tests (by ~11% on my machine), as well as running benchmarks without measuring I/O, which was the initial motivation.

Commits:

  • f539802: Refactoring only. Introduces CacheStore, which provides caches for classpaths, abstract files (by name), and source files. The default DefaultCacheStore preserves the current behavior: a singleton global cache for ClassPath instances, and no-op caches for files and sources (which are still cached per run via ContextBase).
  • 8823120: Uses a custom CacheStore for compilation tests that caches SourceFile and AbstractFile instances across runs, avoiding repeated reads of the standard library from disk.
  • f17e93b: Fixes the output of the wrong-owner test to list context owners instead of all outer contexts. This is needed because ctx.fresh adds an outer context that would otherwise introduce an extra <none>.
  • 254b87c: Adds a cache in CacheStore for class file bytes. The default is to not cache them. The test cache is updated to cache class bytes globally.
  • 8d322fa: Adds a cache in CacheStore for TASTy file bytes, analogous to the class-file cache.

@mbovel mbovel force-pushed the mb/caches-refactor branch 2 times, most recently from 72576c7 to 364039a Compare December 19, 2025 19:18
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