From 38d5a65323e8ef0e09f54420f40da092ea8052a0 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Fri, 9 Oct 2026 21:55:08 +0000 Subject: [PATCH] =?UTF-8?q?Bolt:=20[=EC=84=B1=EB=8A=A5=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0]=20=EA=B2=80=EC=83=89=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EC=A7=91=EA=B3=84=20=EB=A3=A8=ED=94=84=20=EB=B0=8F=20=EC=A7=91?= =?UTF-8?q?=ED=95=A9=20=EA=B5=90=EC=A7=91=ED=95=A9=20=EC=97=B0=EC=82=B0=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `transcript_search.py`의 검색 루프 내부에서 사용되던 제너레이터 기반의 `sum()` 호출을 일반 `for` 루프로 풀어서(unrolling) 전개하고, 집합의 교집합 연산(`&`)을 제자리(in-place) 연산인 `.intersection_update()`로 변경하여 메모리 사용량 및 실행 시간을 최적화함. --- .jules/bolt.md | 4 ++++ transcript_search.py | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 341c7c91..373455e5 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -67,3 +67,7 @@ ## 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. + +## 2026-06-28 - [집합 교집합 및 반복문 루프 최적화] +**Learning:** `sum()`과 제너레이터 표현식을 타이트한 이너 루프에서 사용하면 제너레이터 인스턴스화 오버헤드가 발생하며, `set`의 `&` 연산자 역시 매번 새로운 집합을 생성하여 비효율적이다. +**Action:** 타이트한 루프에서는 제너레이터 대신 일반 `for` 루프를 사용하고, 집합의 교집합은 새로운 객체를 생성하지 않는 `.intersection_update()`를 사용하여 메모리와 시간을 절약한다. 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,