Skip to content

perf: profile and speed up slow unit tests #1181

@Jammy2211

Description

@Jammy2211

Overview

Some unit tests in PyAutoFit run slower than necessary. This task profiles the test suite to identify the slowest tests and applies targeted optimizations to reduce total test runtime. Numerical correctness will be preserved — any changes to test values will be flagged for review. At the end, a reusable prompt will be produced so the same process can be applied to PyAutoGalaxy and PyAutoLens.

Plan

  • Profile the full PyAutoFit test suite to identify the slowest tests
  • Analyze bottlenecks (large arrays, unnecessary iterations, expensive fixtures)
  • Apply targeted speedups without changing numerical reference values where possible
  • Re-profile to validate improvements
  • Produce a reusable prompt for applying the same process to PyAutoGalaxy and PyAutoLens
Detailed implementation plan

Affected Repositories

  • PyAutoFit (primary and only repo for this task)

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
PyAutoFit main_build clean

Suggested branch: feature/unit-test-profiling

Implementation Steps

  1. Run pytest test_autofit --durations=0 -q to collect timing data for all 1198 tests
  2. Identify the top 30+ slowest tests and read their source to understand bottlenecks
  3. Categorize slow tests: search iterations, large arrays, database I/O, fixture overhead
  4. For each category, apply safe optimizations (reduce sizes, scope fixtures, trim iterations)
  5. Flag any tests where numerical values would change — get user approval before modifying
  6. Re-run full suite to confirm all tests pass and measure improvement
  7. Write a reusable prompt file for PyAutoGalaxy and PyAutoLens

Key Files

  • test_autofit/ — 169 test files, 1198 tests
  • test_autofit/conftest.py — shared fixtures
  • test_autofit/non_linear/ — likely hotspot (search algorithm tests)
  • test_autofit/graphical/ — likely hotspot (EP/graphical model tests)
  • test_autofit/database/ — likely hotspot (database I/O tests)

Original Prompt

Click to expand starting prompt

This is a generic source code improvement that applies to all five PyAuto repos.

Basically, some unit test run slow, and this dev work aims to profile the unit tests
and speed them up as much as possible. We dont want to change numerical values on unit
tests where possile, hwoever I am also confident currently that the source code is stable
thus for the slower unit tesrts if there are safe changes we can make to speed them up, then we should do so,
but prompt me on the.

To begin, can we run this on PyAutoFit and I'll see how it goes and we
can then run it on the other repos.

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