⚡ Bolt: O(N) Precomputation in 3-Way Match#32
Conversation
Refactored `execute_3_way_match` in `src/plugins/supply_chain.py` to precompute normalized descriptions and tokens for candidates outside the inner loop. What: Created `_prepare_candidates` function and updated matching functions to accept precomputed tokens instead of raw strings. Why: Previously, `_normalize_description` and string tokenization were repeatedly executed inside a nested loop comparing `invoice_items` against `po_lines` and `receipt_lines`. This resulted in O(N*M) string and regex operations, slowing down execution for large item lists. Impact: Reduces time complexity of string/regex operations from O(N*M) to O(N+M), significantly improving matching speed. In tests, it reduced execution time from ~0.98s to ~0.17s (~82% speedup). Measurement: Tested logic and performance with isolated benchmark. Tests confirmed correct execution and expected speedup. Co-authored-by: kourdroid <36898160+kourdroid@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Added
_prepare_candidatesto precompute normalized descriptions and tokens. Updated_match_scoreand_find_best_matchto accept precomputed values instead of calculating them for every comparison. Updatedexecute_3_way_matchto use the precomputed candidates.🎯 Why:
_normalize_descriptionand tokenization operations were inside the inner loop of a nested loop checking every invoice item against every PO line and receipt line. This caused O(NM) expensive string operations which caused a bottleneck for larger lists.📊 Impact: Reduces time complexity of the repetitive string operations from O(NM) to O(N+M), drastically improving performance (measured ~82% speedup).
🔬 Measurement: Verified functionality using
pytesttest suite, verified speedup using benchmark script, and verified code usingflake8.PR created automatically by Jules for task 6760937199755700660 started by @kourdroid