From e2399f99fd6b739a6161f69136c0f585048326b4 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 8 Oct 2026 20:52:39 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EC=84=B1=EB=8A=A5=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit πŸ’‘ μž‘μ—… λ‚΄μš©: 검색 인덱슀의 닀쀑 단어 쿼리 ꡐ집합 계산 μ΅œμ ν™” 및 점수 ν•©μ‚° 루프 μ˜€λ²„ν—€λ“œ 제거 🎯 μž‘μ—… 이유: 큰 κ²°κ³Ό μ§‘ν•©μ΄λ‚˜ λ§Žμ€ λ¬Έμ„œμ— λŒ€ν•œ ꡐ집합 계산 및 점수 λ„μΆœ μ„±λŠ₯을 λ†’μ—¬ 응닡 μ‹œκ°„μ„ 단좕 πŸ“Š μ˜ˆμƒ 효과: 단어 μ‘°ν•© κ²€μƒ‰μ—μ„œ λΆˆν•„μš”ν•œ set 볡제 제거 및 generator 생성 λΉ„μš© 제거 πŸ”¬ μΈ‘μ • 방법: benchmark script μˆ˜ν–‰ μ‹œ 처리 μ‹œκ°„κ³Ό 피크 λ©”λͺ¨λ¦¬ κ°μ†Œ 확인 --- .jules/bolt.md | 3 +++ transcript_search.py | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 341c7c91..96ca427f 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -67,3 +67,6 @@ ## 2025-02-12 - [Fast Path Execution in Directory Traversal and Log Parsing] **Learning:** Checking for string existence (`if "silence_" not in stderr`) before invoking regex matchers provides significant speed improvements when parsing large blocks of text. Similarly, moving expensive I/O operations like `os.path.realpath` inside conditional blocks prevents redundant disk access when configuration (like path exclusions) isn't utilized. **Action:** When working on large text processing or disk operations, verify if early exit conditions or conditional execution can bypass the expensive system or library calls. +## 2024-10-08 - [Optimize Search Set Intersection and Loops] +**Learning:** In tight loops involving `set`s (like when computing the intersection of matching documents for multi-word search terms), creating a new `set` with the `&` operator allocates memory and iterates needlessly. Modifying a target `set` in place using `.intersection_update()` avoids this allocation. In the same vein, using `sum()` with a generator expression introduces significant overhead due to object allocation of the generator. Replacing it with a simple `for` loop that accumulates in a local variable provides a substantial speedup. +**Action:** Always prefer `intersection_update` over `&` when working with sets you can modify safely. For performance-sensitive loops, replace `sum(a for b in c)` with a basic inline `for` loop to eliminate the generator overhead. diff --git a/transcript_search.py b/transcript_search.py index 1660c1f2..beb304c6 100644 --- a/transcript_search.py +++ b/transcript_search.py @@ -241,16 +241,19 @@ def search(self, query: str) -> list[Match]: postings = self._postings.get(term) if not postings: return [] - candidates = ( - set(postings) if candidates is None else candidates & postings - ) + if candidates is None: + candidates = set(postings) + else: + candidates.intersection_update(postings) if not candidates: return [] matches = [] for position in candidates or (): entry = self._entries[position] - score = sum(entry.counts[term] for term in unique_terms) + score = 0 + for term in unique_terms: + score += entry.counts[term] matches.append( Match( recording_id=entry.recording_id,