Skip to content

perf: profile and speed up unit tests #251

@Jammy2211

Description

@Jammy2211

Overview

Some unit tests run slow. This task profiles the PyAutoArray test suite to identify the slowest tests, diagnose bottlenecks, and apply targeted optimizations. The outcome will include a reusable prompt template that can be applied to PyAutoGalaxy and PyAutoLens afterward.

Plan

  • Profile the full PyAutoArray test suite to rank all tests by duration
  • Identify and categorize the slowest tests by bottleneck type (computation, fixtures, I/O)
  • Deep-profile the worst offenders with cProfile to find specific hot functions
  • Propose targeted speedups for approval before making changes
  • Implement approved optimizations and re-profile to confirm improvement
  • Produce a reusable prompt for applying the same process to PyAutoGalaxy and PyAutoLens
Detailed implementation plan

Affected Repositories

  • PyAutoArray (primary and only)

Work Classification

Library

Branch Survey

Repository Current Branch Dirty?
PyAutoArray main untracked files only

Suggested branch: feature/unit-test-profiling

Implementation Steps

  1. Run pytest --durations=0 on PyAutoArray to get a ranked list of all test durations
  2. Categorize the slowest tests by directory and bottleneck type
  3. Profile individual slow tests with cProfile to pinpoint hot functions
  4. For each slow test, identify root cause: oversized inputs, redundant setup, expensive computation, unnecessary I/O
  5. Present findings with proposed fixes for user approval
  6. Implement approved changes, verifying each test still passes
  7. Re-run full suite to confirm all tests pass and measure overall speedup
  8. Write a reusable prompt template (with lessons learned) for PyAutoGalaxy and PyAutoLens

Key Files

  • test_autoarray/conftest.py — 70+ fixtures
  • test_autoarray/inversion/ — 36 test files (likely hotspot)
  • test_autoarray/structures/ — 26 test files
  • test_autoarray/profile_tst.py — existing profiling script

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 PyAutoArray 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