Repository navigation
perf: check class scripts and served files in the cache once a minute, not every render - #366
Merged
Merged
Conversation
…, not every render Every render asked the cache backend about each component's JS and CSS and each served Dependencies file. It read both the versioned and the stable key back and compared the payloads, or ran `has` and then read the served file back. With a shared backend such as Redis, that was several network round trips per component per render. The engine already remembers, for the compiled Vue assets, which keys it saw stored, and asks again at most once a minute (`_store_if_missing`). These entries now use the same record: - The versioned script key and a served file are named by their content, so they use `_store_if_missing`. - The stable script key's value changes with the class, so a new `_store_unless_matched` compares it, at most once a minute for one class version, and rewrites it when it differs. - Emission uses the served file's content in hand instead of reading the entry back, which removes the TypeError path for a missing entry. - A request that finds a versioned key or a served file missing makes its process forget the key. A class script is then written back at once, and a served file on this process's next render. - `reset_files()` forgets the keys it deletes. - A key that is checked stays at the recent end of the record, so the record's size limit drops the keys no page links any more. One contract changes. If the backend drops a served `Dependencies` file, other workers can answer 404 for it for up to a minute, the same trade-off the Vue assets make. A class script is still written back by the first request for it; a render now trusts its record for up to a minute instead of rewriting it at once, and the test that locked the old behavior now locks the new one. The css_data() stylesheets are left for a separate change, with the bound #154 asks for. Refs #154 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
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.
Refs #154. This is part 1, the cache round trips. Part 2 (the default cache growing with each distinct
css_data()value) and thecss_data()stylesheets' round trips follow separately, once the bound is decided.What changes
Every render asked the cache backend about each component's JS and CSS, and about each served
Dependenciesfile:hason a served file, then read the file back.With Redis, that was several network round trips per component per render.
The engine already keeps a record of the compiled Vue asset keys it saw stored, and asks the backend again at most once a minute (
citry.cache._store_if_missing). These entries now use the same record:_store_if_missing._store_unless_matchedcompares it, at most once a minute for one class version, and rewrites it when it differs. Citry never serves the stored stable value, because each worker returns the object built from its own class.TypeErrorpath the issue mentions.reset_files()forgets the keys it deletes.One contract changes. If the backend drops a served
Dependenciesfile, other workers can answer 404 for it for up to a minute, the same trade-off the Vue assets make.docs_site/content/performance/cache-backends.md("Temporary 404s") already describes this in general terms.Tests
New, in
tests/test_deps_emission.py:reset_files()writes the class entries again at once.Mutations were checked against these tests: each new forget, the comparison against the mark, and the compare in
_store_unless_matched.Changed:
test_class_capture_repairs_evicted_shared_cachetest_a_request_for_an_evicted_version_writes_it_back_at_once(new)Evidence
Run on this branch, based on main 2640d24, with citry_core built from main b3491f0:
packages/py/citry/testsandpackages/py/citry_ui/tests(-m "not e2e"): 9,585 passed.test_render_body_snapshots.py::test_an_error_three_levels_deep_matches_the_snapshotcases fail the same way on origin/main with that citry_core build, because main has newer Rust. PR CI builds fresh Rust.--platform linux).This change has no Rust; PR CI runs the cargo phases.
Review
An independent review with a separate prose pass is folded in:
cache_component_jsdocstring and design-doc sentence;🤖 Generated with Claude Code