Skip to content

Cache CompiledConfig across runs in watch mode #28

@goulvenclech

Description

@goulvenclech

Problem

CompiledConfig::compile() takes ~30 ms and accounts for ~99% of the full pipeline. In a future watch mode, recompiling on every file change is wasteful since the config rarely changes.

Proposed solution

Cache the CompiledConfig in memory and skip recompilation when the config inputs haven't changed.

Requirements

  • In-memory onlyCompiledConfig contains Regex, RegexSet, and fn pointers (Rule::Dynamic). Not serializable to disk.
  • Invalidation trigger — recompile only when config source changes:
    • Built-in presets: static, never change within a binary run. No invalidation needed.
    • Future user config file (TOML/etc.): invalidate on file mtime/content hash change.
  • StorageArc<CompiledConfig> shared across iterations. Replace on invalidation.
  • Scope — this is a building block for a watch mode / dev server, not useful in the current one-shot CLI.

Suggested approach

  1. Extract config construction into a function returning a content hash + CompiledConfig.
  2. On each watch iteration, rebuild config inputs, compare hash. If unchanged, reuse cached Arc<CompiledConfig>.
  3. Expected improvement: pipeline per rebuild drops from ~30 ms to ~0.2 ms (~150x).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions