Repository navigation
perf: cache config YAML/JSON parsing — one parse per file per process - #212
Merged
Merged
Conversation
…#211) Config.push/register invalidate the lazily-built config dict and prior config, so every library import re-read every config file from disk. autonerves.parse_cache parses each file once, keyed on absolute path and (mtime_ns, size), and returns a deep copy so results equal a fresh parse. Routed through YAMLConfig, JSONPriorConfig.from_directory and Config.logging_config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016nhQ8NkMVDS9RLqr6FRXye
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.
Closes #211.
What
Config.push/Config.registerreset the lazily-built config dict and prior config, so after every library import the next access re-read every config file from disk. The newautonerves/parse_cache.pyparses each file once per process:(st_mtime_ns, st_size)match, so editing a file re-parses it as beforecopy.deepcopyof the cached object, so a caller mutating a loaded config can never affect a later loadyaml.safe_load/json.load, looked up at call timeRouted through the three config-loading paths:
YAMLConfig.__init__,JSONPriorConfig.from_directory(JSON + YAML priors) andConfig.logging_config. No public API change: theimport yamllines stay in place, so no module attributes are removed. The one-offgeneral.yamlreads in__init__.pyandworkspace.py, andsite_config, are left alone because they run once per process anyway.Witness
test_cached_parse_deep_equals_fresh_parsebuildsConfig.dict,JSONPriorConfig.from_directory(<dir>/priors).objandlogging_configfrom fresh parses, then from the cache (cold and warm), and deep-compares them over every packaged config directory in the repo (config,config_flip,default,site). I also ran the same comparison by hand, outside CI, over the shipped and test configs of PyAutoFit, PyAutoArray, PyAutoGalaxy and PyAutoLens (8 directories). All 8 were deep-equal.yaml.safe_loadhook counted parses. In a simulated register sequence (galaxy test config + push autofit → autoarray → autogalaxy → autolens → autolens test config, withdictandprior_configread after each push), parses went from 468 (148 distinct files, up to 8× each) to 148 (each file exactly once). In the repo,test_each_file_parsed_once_across_pusheschecks that no file is parsed more than once.visualization.pyitself because the workspace isn't in this session, so the end-to-end ≥0.8 s figure should be confirmed on a real script run.Tests
python3 -m pytest -q -n auto: 301 passed, 1 skipped (the base had 291 passed; the 10 new ones are intest_autonerves/test_parse_cache.py, covering deep-compare, parse once, independent copies, mtime invalidation, missing file not cached, and json/yaml kinds kept separate).Tier: notify. Batch 2026-11-08-am: the session ends at PR-open, and merge is the human's
/prm.Generated by Claude Code