Skip to content

perf(settings,inertia): cache settings source metadata; pre-serialise the i18n catalog - #835

Merged
antosubash merged 9 commits into
mainfrom
fix/s12-perf-settings-inertia
Nov 5, 2026
Merged

antosubash merged 9 commits into
mainfrom
fix/s12-perf-settings-inertia

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Performance fix for two hot paths found by the 2026-11-05 load test.

Settings pages / GET /api/settings/modules rebuilt pydantic settings sources (env, .env, secrets dir) for every module settings class on every request.

  • simple_module_core.settings_hydrate.env_supplied_fields and simple_module_hosting._api_version.default_api_version are cached per class per process.
  • Behaviour change: changing environment variables, .env or the secrets directory now needs a restart. That was already true for the running app's settings; only the settings screen's "set by env" marker and the env-pinned write guard read the live environment before.
  • The shared test plugin (simple_module_test.process_state) clears both caches around every test. Tests that set env mid-test clear them explicitly to simulate a restart.

Inertia page encoding walked and re-encoded the shared i18n catalog (~70–90 KB, static per locale + audience) on every full page load.

  • The catalog is serialised once per (registry, locale, audience, snapshot) as a JsonSnapshot, in simple_module_inertia._json_snapshot and simple_module_hosting._i18n_json.
  • Page encoding splices that snapshot in at props.i18n.messages, skipping _resolve_tree and the plain-JSON walk for it.
  • Output is byte-identical for both the JSON response and the HTML data-page, escaping included. Partial reloads and X-SM-I18n-matched visits behave as before.

Median CPU per operation, 87 KB catalog:

Path Before After
Settings modules view 7.72 ms 3.07 ms
Inertia page JSON 1.36 ms 0.24 ms
HTML page JSON 1.55 ms 0.31 ms

Pipeline: /optimize (1 commit), correctness + maintainability review. Review fixes:

  • a registry that cannot be weak-referenced is served uncached instead of returning 500;
  • the snapshot module was renamed so it no longer shadows the stdlib json;
  • reviewers confirmed every app entry point loads .env before the cache fills.

Local CI:

  • make lint ✓ and make test-js ✓.
  • make test-py (8 workers): one failure, a local stale __pycache__ directory left by the merged dashboard module move. It passes once that is removed, and it does not exist in CI.

https://claude.ai/code/session_01M9neheZZEe3sVpDi2S3zT4

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-11-05T16:51:27.481670Z 7f206bd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: f7e2698
Status: ✅  Deploy successful!
Preview URL: https://4cafb75c.simple-module-python.pages.dev
Branch Preview URL: https://fix-s12-perf-settings-inerti.simple-module-python.pages.dev

View logs

# Conflicts:
#	CHANGELOG.md
# Conflicts:
#	CHANGELOG.md
@antosubash
antosubash merged commit 0646d66 into main Nov 5, 2026
17 checks passed
@antosubash
antosubash deleted the fix/s12-perf-settings-inertia branch November 5, 2026 23:11
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