Repository navigation
render: opt-in reuse-only input cache (--exp-input-cache) - #1421
Draft
MatejKozlovsky wants to merge 2 commits into
Draft
MatejKozlovsky wants to merge 2 commits into
MatejKozlovsky wants to merge 2 commits into
Conversation
…layer cache budget Layer results are admitted on their second render, stored cropped to their pixels (64-px grid) and served at their full extent and origin, so output is byte-identical to an uncached render. A hot cropped entry keeps one full-extent copy (one copy and one GPU upload, not one per frame) only within the budget; eviction keeps entries reused every frame over a cycle bigger than the budget. Off by default; --exp-input-cache or EFFECTCRAFT_EXP_INPUT_CACHE=1 turns it on.
… expansions until the new copy fits, and the env switch is read by the CLI
Contributor
Author
|
Parking this as a draft for now. It's the one change with a measured 3–6× on the text and blur/glow samples, but those are the same samples #1441 and #1523 target, and I want to re-measure it on top of them before asking for review. Known fixes before un-drafting: the |
MatejKozlovsky
marked this pull request as draft
October 17, 2026 19:55
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An opt-in mode for the layer cache (
--exp-input-cache, orEFFECTCRAFT_EXP_INPUT_CACHE=1), off by default:exactly like the default cache, so projects that fit their budget behave as they do on
main.only when it's rendered a second time, so one-off results never push reused ones out.
pixels (plus a 2 px margin), but only when the crop is at most a quarter of the frame. Marginal
crops cost a scan plus a full-extent copy on each hit for little memory. Hits are served at the
full extent and origin, with the original buffer's offset restored bit for bit (not recomputed
from the crop's), so output is byte-identical to an uncached render.
copy and one GPU upload, not one per frame), but only within the budget: other entries' copies
are dropped, least recently used first, until the new copy fits; if it still doesn't, the hit
goes without one.
budget, instead of being LRU-evicted just before they're needed.
Based directly on
main. It doesn't depend on #898 or any other open PR. The switch is a smallstatic in
render::cachethat the CLI sets (the CLI also readsEFFECTCRAFT_EXP_INPUT_CACHE; therender crate reads no environment), so there's no new settings plumbing.
EFFECTCRAFT_CACHE_STATS=1also reports how many inserts were stored cropped.
Results
GPU render (
--gpu), RTX 3090, 30 frames, H.264, benchmark resolution (4K samples at half), layercache budget 1024 MB (the default), 3 runs each, interleaved:
--exp-input-cacheThe gain is on projects whose reused layers don't all fit the budget (b, d). An earlier version
was slower on c and f. Profiling showed two causes:
full-extent copy of a cropped entry. Results are now stored at once while under budget.
frame cost the scan plus per-hit copies. The crop threshold went from 75% to 25% of the frame.
With crop thresholds of 25% and 50%, b and d stay at 15 s and 5.5 s. With cropping off, they
drop back to about 17.8 s and 7.6 s.
Output
Byte-identical to
main(per-frame MD5, 15 PNG frames each) on samples b, c, d and f and on threesmall tailored projects (a single blur/glow layer, a single 10-effect layer, and a 4K full-stack
layer):
Earlier run-to-run differences seen on b/f came from #898's adaptive CPU workers. They render a
timing-dependent set of frames on the CPU, and CPU and GPU differ by up to 2 levels. That has
nothing to do with this change, and this branch (on
main) has no such scheduler.Testing
cargo fmt --allcargo clippy -p effectcraft-render -p effectcraft-cli --all-targets -- -D warnings: clean.cargo test -p effectcraft-render: 221 passed, 0 failed, 1 ignored.cropped_entries_come_back_bit_for_bit_with_fractional_offsets: cropped entries under pressurecome back with the same pixels and bit-identical offsets (fractional, -0.0, large). It fails with
the old
offset - x0 + x0restore.reuse_only_cache_under_pressure_crops_and_matches_uncached: a render under a tight budget withsmall masked patches at fractional positions; asserts some entries were stored cropped and every
frame is byte-identical to an uncached render.
reuse_only_admits_at_once_within_the_budget_and_on_reuse_over_it,reuse_only_cache_matches_uncached_with_expressions_and_time_effects.