Skip to content
Open
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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

## 2025-02-12 - [Optimize inverted index intersection loops]
**Learning:** Initializing the intersection base with `set(postings)` adds an unnecessary shallow copy for the first item and increases the critical path overhead by 2-3x for single-term queries. Python's `set.intersection` and `&` operators generate new sets, making it safe to use the bare reference as the intersection seed as long as it isn't mutated directly.
**Action:** When implementing intersection logic inside hot loops over inverted indices, seed the accumulator directly with a reference (`candidates = postings`) rather than creating a shallow copy (`candidates = set(postings)`). Ensure inline comments explain why this avoids mutation bugs.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
### Fixed
- 단일·일괄 대상 크기 입력을 비웠을 때 이전 custom validity와 `aria-invalid` 상태를 즉시 초기화해 현재 필수 입력 상태를 정확히 전달합니다.
- 업로드 파일명의 경로 구분자를 정규화하여 POSIX에서도 Windows 형식의 클라이언트 경로가 일관된 basename으로 기록되도록 수정했습니다.

### Performance (최적화)
- `transcript_search.py`에서 불필요한 set 객체 생성 및 복사를 제거하여 검색 속도를 최적화했습니다.
9 changes: 9 additions & 0 deletions tests/test_transcript_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ class MissingText:
idx.add("bad", [MissingText()])
self.assertIn("attribute", str(ctx.exception))

def test_search_performance_no_mutation(self):
"""Verify that search does not mutate the internal index when skipping set copies."""
idx = TranscriptIndex()
idx.add("rec", [Segment(0, 1, "hello world")])
postings_before = len(idx._postings["hello"])
matches = idx.search("hello")
self.assertEqual(len(matches), 1)
self.assertEqual(len(idx._postings["hello"]), postings_before)

def test_search_returns_empty_when_postings_intersection_is_empty(self):
"""Known terms with disjoint postings produce no matches."""
idx = TranscriptIndex()
Expand Down
7 changes: 6 additions & 1 deletion transcript_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,13 @@ def search(self, query: str) -> list[Match]:
postings = self._postings.get(term)
if not postings:
return []
# Performance optimization:
# We avoid creating a shallow copy via set(postings) for the first term.
# This is safe because python's `&` operator returns a new set on subsequent
# iterations, and the returned `candidates` reference is only used locally
# to generate Match objects, never mutated or exposed to the caller.
candidates = (
set(postings) if candidates is None else candidates & postings
postings if candidates is None else candidates & postings
)
if not candidates:
return []
Expand Down
Loading