perf: Vectorize O(n²) pairwise contrast check in thread_manager #28

Closed
opened 2026-06-10 05:46:01 +00:00 by Mark · 0 comments
Owner

Problem

thread_manager.py:270 — O(n²) nested loop comparing every pair of thread colors for luminance contrast.

Proposed Fix

Vectorize with numpy: compute luminance array, then use broadcasting for pairwise differences.

Impact

5-20x faster for thread color palette validation.

Files

  • src/embroidery_converter/thread_manager.py:260-287
## Problem `thread_manager.py:270` — O(n²) nested loop comparing every pair of thread colors for luminance contrast. ## Proposed Fix Vectorize with numpy: compute luminance array, then use broadcasting for pairwise differences. ## Impact 5-20x faster for thread color palette validation. ## Files - `src/embroidery_converter/thread_manager.py:260-287`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/easystitch#28
No description provided.