From 4089df6b08d533d838ce0bf4166078faeccdd9d7 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 10 Oct 2026 17:24:00 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20=EA=B2=80=EC=83=89=20=EC=8B=9C=20?= =?UTF-8?q?=EC=84=B8=ED=8A=B8=20=EA=B5=90=EC=A7=91=ED=95=A9=20in-place=20?= =?UTF-8?q?=EC=97=B0=EC=82=B0=EC=9C=BC=EB=A1=9C=20=EB=A9=94=EB=AA=A8?= =?UTF-8?q?=EB=A6=AC=20=ED=95=A0=EB=8B=B9=20=EC=B5=9C=EC=86=8C=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..6efd4673 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 Intersections in Hot Loops] +**Learning:** Using the `&` operator for set intersections creates intermediate sets, leading to unnecessary memory allocations and performance degradation inside hot loops. +**Action:** Use the in-place `.intersection_update()` method when sequentially intersecting sets to mutate the existing set directly, avoiding intermediate allocations. diff --git a/transcript_search.py b/transcript_search.py index 1660c1f2..3f1e1333 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: Use .intersection_update() for in-place set intersection to avoid intermediate memory allocations and improve execution speed. + candidates.intersection_update(postings) if not candidates: return []