From 697b8703701eeb94ffdfdabee3660534410f7bf5 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:36:54 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EA=B5=90=EC=A7=91=ED=95=A9=20=EC=97=B0=EC=82=B0=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94=20(intersection=5Fupdate)?= 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..f4b4f575 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-06-25 - [Optimize set intersection in hot loops] +**Learning:** Using the `&` operator in a loop creates a new intermediate set in memory during each iteration. When repeatedly intersecting sets, `.intersection_update()` modifies the set in-place, preventing allocations and reducing overhead. +**Action:** Replace `&` with `.intersection_update()` when repeatedly intersecting sets in performance-critical loops. diff --git a/transcript_search.py b/transcript_search.py index 1660c1f2..2ffdb706 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: + # 불필요한 중간 집합(set) 생성을 방지하기 위해 in-place 교집합 업데이트 사용 + candidates.intersection_update(postings) if not candidates: return []