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 @@ -63,3 +63,7 @@
## 2024-07-30 - Avoid chained string replace when checking character sets
**Learning:** Using chained `.replace(a, "").replace(b, "")` to check if a string consists entirely of specific characters requires intermediate string allocations for every call. In benchmarks, using `.strip("ab")` is ~30% faster and avoids multiple allocations in the hot path.
**Action:** When checking if a string is solely composed of specific characters, use `.strip(chars)` instead of chained `.replace()` calls to improve performance.

## 2024-07-31 - Use isspace() instead of strip() for visible text checks
**Learning:** Checking if a string contains visible text by evaluating `bool(text.strip())` forces the allocation of a new string just to test its truthiness. Using `.isspace()` avoids this memory allocation and is significantly faster in hot loops.
**Action:** Replace `bool(text.strip())` with `not text.isspace()` when checking if a string contains visible characters to avoid unnecessary string allocations.
4 changes: 2 additions & 2 deletions src/newsdom_api/equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def _article_has_headline(article: dict[str, Any]) -> bool:
return headline_present

headline = article.get("headline")
# โšก Bolt: Early truthiness return to avoid allocating a stripped string when it is empty
return isinstance(headline, str) and bool(headline) and bool(headline.strip())
# โšก Bolt: Use .isspace() instead of .strip() to avoid string allocation when checking for visible text
return isinstance(headline, str) and bool(headline) and not headline.isspace()


def _process_articles(metrics: dict[str, Any], articles: list[Any]) -> None:
Expand Down
Loading