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
@@ -0,0 +1,3 @@
## 2024-05-24 - [Cache Unnecessary Python Loop Variables]
**Learning:** In highly recursive or looping NLP functions such as line-by-line regex scanning, rebuilding configurations or alias lookups dynamically creates enormous overhead in Python. The openmed package's `_alias_lookups` recreated language alias dicts on every single line, leading to severe slowdowns.
**Action:** Use `@functools.lru_cache(maxsize=None)` on deterministic configuration generators within loops to cut down redundant operations. Ensure inputs are hashable and small in variance (like language codes).
4 changes: 4 additions & 0 deletions openmed/openmed/clinical/sections/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import functools
from collections.abc import Iterable, Mapping
from dataclasses import dataclass
from typing import Any
Expand Down Expand Up @@ -244,6 +245,9 @@ def _is_underline(text: str) -> bool:
return len(stripped) >= 3 and set(stripped) <= _UNDERLINE_CHARS


# Bolt ⚡: Cache alias lookups as they are static per language to prevent
# redundant tuple/dict allocations on every line during clinical section detection.
@functools.lru_cache(maxsize=None)
def _alias_lookups(language: str | None) -> tuple[tuple[str, Mapping[str, str]], ...]:
languages = (
tuple(dict.fromkeys((get_section_lexicon(language).language, "en")))
Expand Down
2 changes: 2 additions & 0 deletions openmed/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.