perf(config): mtime-signature fast path for load_config - #410
Conversation
load_config re-read and re-parsed config.json, the secrets file, AND the template (running the recursive migration diff) on every call — with ~30 call sites in web request handlers, some hit 2-3x per request. Fast path: stat all three files (mtime_ns + size); when unchanged since the last successful load, return the already-parsed self.config (same aliasing semantics as before). The signature is taken AFTER load + migration so a migration write-back doesn't retrigger, and both save paths refresh it. Cross-process freshness is preserved by construction: a save from the other process bumps the file mtime, so the next load here re-reads — verified by a dedicated test. Same-second edits are caught by mtime_ns plus a size check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FqzC1nzTWL4kaqgMaQZFam
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesConfig Cache
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ConfigManager
participant ConfigFiles
ConfigManager->>ConfigFiles: Compute mtime_ns and size signature
ConfigFiles-->>ConfigManager: Return current signature
ConfigManager->>ConfigManager: Compare with _loaded_sig
ConfigManager-->>ConfigManager: Return cached config or load files
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Summary
PR 6 of the performance series.
load_config()did full work on every call — 3 file reads + 3 JSON parses + a recursive template-migration diff — and it's called from ~30 web request handlers, several 2–3× per request.Now: 3
os.statcalls; if the (mtime_ns, size) signature of config/secrets/template is unchanged since the last successful load, return the already-parsedself.config(identical aliasing semantics to the full path). Signature taken after load+migration so migration write-backs don't retrigger; both save paths refresh it; rollback and raw-file writes self-invalidate through the mtime they change.Cross-process freshness preserved by construction — the web process's save bumps the mtime, so the display process's next call re-reads (dedicated test). Same-second edits caught by mtime_ns + size.
Verification
7 new tests: zero file opens on the fast path (counted via monkeypatched
open), reload on each of the three files changing, same-mtime/different-size edit detection, save-then-load coherence with secrets preserved, and the cross-process pickup. Full config-related suites green (the 2 failures are the pre-existing order-dependentTestConfigAPIdouble-sided ones on main).🤖 Generated with Claude Code
https://claude.ai/code/session_01FqzC1nzTWL4kaqgMaQZFam
Summary by CodeRabbit
Performance
Bug Fixes
Tests