Skip to content

Proposal: per-component render cache versions instead of one RENDER_CACHE_VERSION #1058

Open

Description

@THEtheChad

Summary

Proposal for discussion. There's no PR with it, because this is a design decision for the maintainers.

RENDER_CACHE_VERSION (crates/engine/src/media.rs:65, now 61) is one number covering every rendered thumbnail and view render. It is part of every disk and memory cache key (media.rs:1100, :1142, :1230). The rule is "bump when the pipeline's output changes". In practice:

What is already versioned separately

  • camera_profiles::cache_key() (camera_profiles.rs:156): changes with the profiles folder's contents.
  • camera_preview::LOOK_VERSION (camera_preview.rs:~22): the camera-look fit, for smart-preview proxies.
  • DevelopSettings::process (docs/process-versions.md): deliberate look changes ship as a new process, and the process is inside the settings hash already. So a photo on V1 keeps its cache when V2 lands, without any global bump.

So part of what RENDER_CACHE_VERSION does is already done more precisely elsewhere. What's left is mostly decoder and source changes (per format, often per camera) and bug fixes that land in place (CPU/GPU mismatch, NaN, wrong crop).

Proposal

Replace the single constant with a key made of per-component versions. Each one is bumped only by changes to that component:

  1. Decoder version per format family. For example a decoder_version(format) -> u32 table in lightcraft-raw / lightcraft-codecs (cr3, nef, arw, raf, dng, jpeg, heic, jxl, …), next to the decoders it describes. The render key uses the version of the photo's own format, so a CR3 fix invalidates only CR3 renders. Where a fix is narrower still (one camera model), the table can take the model too, but per-format already removes most of the churn.
  2. Pipeline version for in-place fixes. A small PIPELINE_FIX_VERSION in lightcraft-pipeline, for the bug fixes that docs/process-versions.md allows to land without a new process. Process-level look changes need nothing: the process is in the settings hash.
  3. Camera colour: keep camera_profiles::cache_key(), and add LOOK_VERSION to the render key where the fitted look feeds renders (today it only drives proxy rebuilds).
  4. Optics / lens data: a version for the embedded-lens and lens-profile code paths (LR-EDIT-OPTICS-PROFILE bumps), or fold it into the per-format decoder version when the data comes from the raw's maker notes.
  5. Keep a global RENDER_CACHE_EPOCH for genuinely global changes (cache file format, key layout, output colour management). It should rarely move.

The key becomes hash(content, settings_hash, size, epoch, pipeline_fix, decoder_version(format), camera_profiles::cache_key(), look_version). All of these are compile-time constants or a table lookup, so the key costs no more than today.

Why this also fixes the PR collisions. Two PRs fixing different formats edit different table entries, so the conflict goes away. Two PRs fixing the same format still conflict, and they should, because they need to be reviewed together.

Make the tables hard to forget. A unit test can pin each table entry next to a golden render hash of a tiny procedural sample for that decoder (where one exists), so a decoder change that alters output without a version bump fails CI. This also catches the opposite mistake: a change that alters output but bumps nothing.

Costs and open questions

  • Some fixes touch shared code (demosaic, black levels, the DNG path used by several makes). The author has to decide which formats are affected. Bumping more entries than needed is always safe, and is never worse than today.
  • An existing cache becomes invalid once when the key layout changes. That's one more full re-render, the same cost as any bump today.
  • Where should the tables live so cargo xtask layers stays happy? Probably in the decoder crates (L1), read by engine::media.
  • Is the per-model granularity worth it, given that camera-coverage fixes are usually per model? Per-format first, per-model only if the churn stays high.

Not covered

RENDER_CACHE_VERSION also gates the loupe's "view" render key (media.rs:1222). The same per-component key would apply there unchanged.

Activity

  1. radialmonster commented on Oct 11, 2026

    @radialmonster
    Contributor

    +1. We've been working on the same split. Here's how we'd build it on current main, in small steps that each stand alone.

    1. One fingerprint function, no key change. The persistent key is built inline in three places in media.rs: build_job (:1100), variant_key (:1142) and view_key (:1230), with a fourth copy in the pinned test (:1524). They all hash the content key, the settings hash, a size or kind tag, RENDER_CACHE_VERSION and camera_profiles::cache_key(), and build_job also adds the denoise salt. A first PR would move them into a single render_fingerprint with extra components that are all 0. A component at 0 adds nothing, so every key stays byte-identical: nothing re-renders, and there's no catalog or version bump. A test checks that the three sites agree and that the result equals today's formula.

    2. A revision per reader. RawFormat now has 17 variants and no per-format revision. Each reader gets a constant starting at 0, and the fingerprint adds the photo's reader revision. A decoder fix then bumps one line and re-renders only that format. Shared code (demosaic, TIFF/LJPEG, the embedded-preview path) stays under the global RENDER_CACHE_VERSION.

    3. Record the reader on the photo. Key by the reader the file actually parses as, not by its extension, so RW2/RWL/Panasonic .RAW share one revision and a DNG named .raw follows DNG. Import already probes the file. Reload (SetContent) records the reader again, and undo restores it. Photos without a recorded reader use the combined revision of all readers, which is how it works today, so their cache is never stale. The field needs the next journal version. That's v8 if #800 lands first, so this step would rebase onto it. The field is only a cache hint, so an older build that drops it falls back to the combined key.

    4. A look revision only where a look is fitted. fitted_look() and file_local_look cover the formats developed from a look fitted to their own JPEG. A LOOK_VERSION change should enter the key only for those photos. Today a look-fit change needs a global RENDER_CACHE_VERSION bump, which re-renders every photo in every library, JPEGs and DNGs included.

    5. Lens and as-shot white balance inputs, later. These change the render without changing the settings hash, so they belong in the fingerprint once steps 1–4 are in.

    Process versions already work. They reach the key through the settings hash (V1 is left out of it, so V1 keys are unchanged), so changes gated behind a process version need nothing from this. One gap: the in-memory lin_key/pre_nr_key leave the process out. That only matters if a process-gated change lands before the linear stage.

    Questions

    • Does this order work, with the refactor first?
    • An offline original that renders from its smart preview is cached under the original's key, so after the drive comes back the proxy render can stay until something else changes. Should the source (original or smart preview) go in the key, or should proxy renders not be stored?
    • Do you want a CI check that flags decoder output changes on sample files without a reader revision bump?

    On granularity: per format first, as you suggest. Two PRs on the same reader can still collide, but on that reader's line instead of one global line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions