Skip to content

Large image templates freeze the window for seconds on every Start #162

Closed

Description

@TMHSDigital

Summary

The image template is reloaded and prepared in pure Python on the Tk main thread every time Start is pressed. Preparation is linear in template pixels, so a large capture blocks the UI for seconds.

Where

  • autoclicker/app/controller.py:48-71, :226-227 (_load_image_target in validate_and_start_clicking)
  • autoclicker/core/image_match.py:106-143 (from_image, _probes)
  • autoclicker/core/image_match.py:337-338
  • autoclicker/gui/features/image.py:45-65 (capture accepts any area of 4 px or more)

Details

_probes builds a Python list with one RGB tuple per pixel and loops over every pixel twice; distinct_colors builds a set of 3-byte slices per row. Measured: 400x300 took 99 ms, 1280x720 took 686 ms, 1920x1080 took 1.9 s with about 160 MB peak. MAX_TEMPLATE_PIXELS allows up to 7680x4320.

Impact

Capturing a whole window or monitor as the template makes the app "Not responding" for 2 s or more before the first click, on every Start (hotkey starts too).

Steps to reproduce

  1. Time PreparedTemplate.from_image(Image.effect_noise((1920, 1080), 64).convert("RGB")): about 1.9 s

Suggested fix

Count colors in C with image.getcolors(maxcolors=w*h) and pick probes from that; choose the anchor row with crop(row).getcolors(). Cache the PreparedTemplate keyed by (path, mtime, size). Consider warning at capture time above about 512x512.

Acceptance criteria

  • Preparing a 1920x1080 template takes under 100 ms
  • Repeated Starts reuse the prepared template

Getting started

  • Relevant files: autoclicker/core/image_match.py, autoclicker/app/controller.py, tests/test_image_target.py
  • How to run tests: make check (Git Bash) or tasks.bat lint, tasks.bat typecheck, tasks.bat test (cmd). Single test: python -m pytest tests/test_x.py::TestClass::test_name --no-cov
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 9968dc8. Severity: medium. Effort: S. audit-key: performance|autoclicker/core/image_match.py|PreparedTemplate.from_image

Activity

  1. added
    priority: medium
    performance
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancepriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions