From 2ca3175fceba61744a1561cf41e05599ac5e57d7 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:26:04 +0000 Subject: [PATCH] =?UTF-8?q?TranscriptIndex.search=20=EB=82=B4=20=EC=84=B8?= =?UTF-8?q?=ED=8A=B8=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 --- .jules/bolt.md | 3 +++ transcript_search.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 341c7c91..4c84e31d 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-11 - Optimize set intersection in TranscriptIndex +**Learning:** In Python, when iteratively intersecting sets within a loop, using the `.intersection_update()` method modifies the set in-place, avoiding intermediate memory allocations compared to the `&` operator. +**Action:** Use `.intersection_update()` for set intersections in hot loops. diff --git a/transcript_search.py b/transcript_search.py index 1660c1f2..36f493df 100644 --- a/transcript_search.py +++ b/transcript_search.py @@ -241,9 +241,11 @@ 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: + # ⚡ Bolt: in-place 교집합 연산으로 중간 세트 메모리 할당 방지 + candidates.intersection_update(postings) if not candidates: return []