Cache StackConfig loads keyed on file identity#17
Open
nicoloesch wants to merge 1 commit into
Open
Conversation
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.
Summary
load_stack_config()re-read and re-parsed the config TOML from disk on every call, uncached, including fromPackageConfigBase.get_config()and.get_engine(), which every consuming package goes through. Adds a process-local cache, keyed on(resolved_path, mtime_ns, size, $OA_ACTIVE_PROFILE, $OA_CONFIG_PATH), so anyfile edit or relevant env var change invalidates automatically. No caller needs to invalidate anything for a normal read. Reuses the
stat()call already made for the permission-mode check, so this costs zero extra I/O.Every read, cached or not, still returns a fresh
model_copy(deep=True), so the public contract is unchanged: callers get an independent, freely-mutableStackConfigexactly as before (verified againstgroundworkers, whichmutates the returned object directly).
save_stack_config()andpatch_active_profile()(the only two functions that write the file) clear the cache immediately after writing.Checklist
feature)uv run pytest -q)uv run ruff check .)