Repository navigation
Description
Summary
With tolerance above 0 and a large search margin, one search takes longer than the watcher's poll interval, so the image thread never sleeps and click timing jitters.
Where
autoclicker/core/image_match.py:146-183(_close_to,_find_tolerant)autoclicker/core/click_engine.py:108,:628-649(_IMAGE_POLL_SECONDS,_watch_image)docs/PERFORMANCE.md:35-44
Details
For each probe color (up to 4), _find_tolerant builds a mask over the whole region (Image.new, difference, split, two lighter, point, crop, darker), then runs a Python loop of up to 2000 candidate checks. Synthetic benchmark, 60x30 template:
| Region | Tolerance | Median per search |
|---|---|---|
| 2560x1080 (max margin) | 8 or 32 | 131 to 138 ms |
| 2560x1080 | 0 | 12 ms |
| 360x330 (default margin) | 8 | 5.8 ms |
While searches ran, a second thread doing 2 ms waits (standing in for the click thread) went from p99 12 ms lateness to p99 48 ms. PERFORMANCE.md lists only exact-search costs.
Impact
Image mode with tolerance and a wide margin keeps a core busy for the whole run, acts on matches about 150 ms old, and adds tens of ms of click jitter. 4K regions are roughly 3x worse.
Steps to reproduce
- Build
PreparedTemplate.from_imagefrom a 60x30 noise image - Time
find_template(Image.effect_noise((2560, 1080), 40).convert("RGB"), tmpl, 8)
Suggested fix
Build the full-region mask for one probe only (the rarest color), then check the remaining probes per candidate with getpixel or small crops. Cache the solid-color image and the point LUT in PreparedTemplate. Optionally sleep max(poll, last_search_time) so the watcher cannot spin. Add tolerant-search figures to PERFORMANCE.md.
Acceptance criteria
- Tolerant search on a 2560x1080 region under 30 ms in the benchmark
- PERFORMANCE.md documents tolerant-search cost
Related: #97
Getting started
- Relevant files:
autoclicker/core/image_match.py,scripts/profile_click_engine.py,docs/PERFORMANCE.md - How to run tests:
make check(Git Bash) ortasks.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: M. audit-key: performance|autoclicker/core/image_match.py|_find_tolerant
Activity
fix(image): wait as long as a slow search took before searching again