Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-07-25 - [transcript_search 성능 최적화]
**Learning:** 교집합을 구할 때 반복문 내에서 `&` 연산자를 사용하면 매번 새로운 set 객체를 할당하므로 메모리와 시간 측면에서 비효율적입니다. `intersection_update`를 사용하여 제자리에서 수정하는 것이 성능상 유리합니다. 또한 제너레이터 표현식과 함께 `sum()`을 호출하는 것은 인스턴스화 오버헤드를 발생시키므로, 내부 루프에서는 단순 inline for 루프를 사용하는 것이 훨씬 빠릅니다.
**Action:** 다중 집합 교집합을 구할 때는 항상 `intersection_update`를 활용하고, 성능에 민감한 루프 내에서의 덧셈은 제너레이터를 피하고 표준 루프로 언롤링하여 사용해야 합니다.
14 changes: 10 additions & 4 deletions transcript_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,22 @@ 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
counts = entry.counts
for term in unique_terms:
score += counts[term]

matches.append(
Match(
recording_id=entry.recording_id,
Expand Down
Loading