Skip to content

perf: cache prior-config lookups (from_dict model deserialization floor) #129

Description

@Jammy2211

Overview

Follow-up authorized off the aggregator profiling arc (PyAutoFit#1375/#1385): the recorded "deeper, not low-hanging" target. cProfile of values("samples_summary") over 100 mock results (12ms/result): 77% is the model load, and most of that is Model.__init__ building default priors from prior config — JSONPriorConfig.path_value_tuples re-sorts the entire flattened config dict on every lookup (the flattened map is cached, the sort is not), and __call__ then linear-scans it, with identical (class, attribute) queries repeating for every prior of every result.

Plan

  • autoconf/json_prior/config.py: cache the sorted path_value_tuples on the instance; memoize __call__ and for_class_and_suffix_path per instance (positive results and KeyError misses — the class-family probe relies on expected misses). Instance-level caches are invalidated naturally: config pushes construct fresh JSONPriorConfig instances, and returned sub-dicts were already aliased across calls today, so no new sharing is introduced.
  • Measure with the merged aggregator harness (summary/model stages, before/after) + cProfile.
  • Suites: autoconf + full PyAutoFit (prior config is load-bearing everywhere).

Worktree: ~/Code/PyAutoLabs-wt/prior-config-cache/ · Branch: feature/prior-config-cache · Repos: PyAutoConf (only; autofit_workspace_test used read-only for measurement).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions