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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ SPDX-License-Identifier: MIT OR Apache-2.0
## 2025-04-12 - Walrus Operator Optimization
**Learning:** Using the walrus operator inside a list comprehension to avoid redundant execution of string methods (like `.strip()`) is an effective and safe micro-optimization. The result of the assignment inside the list comprehension will intentionally leak into the scope of the caller function, but this standard Python behavior does not cause naming conflicts in non-recursive or non-global scopes.
**Action:** Always favor using the walrus operator `:=` in list comprehensions or conditionals when identical string manipulations (e.g., `.strip()`) or expensive evaluation calls appear repeatedly within the identical expression branch.
## 2026-04-14 - Replace Generator Expressions with For Loops in Linear Lookups
**Learning:** In Python performance optimization, replacing a generator expression wrapped in `next()` (e.g., `next((x for x in iterable if condition), default)`) with a standard `for` loop that uses an early `return` can significantly speed up linear lookups by eliminating generator frame allocation overhead.
**Action:** Replace `next((...))` generator patterns with explicit `for` loops and early returns in hot paths or linear lookups. Suppress linting rules like `SIM110` using `noqa` when necessary to maintain this optimization.
14 changes: 12 additions & 2 deletions src/codeweaver/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ def is_doc(self) -> bool:
"""Check if the extension is a documentation file."""
from codeweaver.core.file_extensions import DOC_FILES_EXTENSIONS

return next((True for doc_ext in DOC_FILES_EXTENSIONS if doc_ext.ext == self.ext), False)
# Performance: Replace generator expression with explicit loop and early return
# to eliminate generator frame allocation overhead during linear lookup.
for doc_ext in DOC_FILES_EXTENSIONS: # noqa: SIM110
if doc_ext.ext == self.ext:
return True
return False

@property
def is_code(self) -> bool:
Expand All @@ -259,7 +264,12 @@ def is_data(self) -> bool:
"""Check if the extension is a data file."""
from codeweaver.core.file_extensions import DATA_FILES_EXTENSIONS

return next((True for data_ext in DATA_FILES_EXTENSIONS if data_ext.ext == self.ext), False)
# Performance: Replace generator expression with explicit loop and early return
# to eliminate generator frame allocation overhead during linear lookup.
for data_ext in DATA_FILES_EXTENSIONS: # noqa: SIM110
if data_ext.ext == self.ext:
return True
return False

@property
def as_source(self) -> ChunkSource:
Expand Down
Loading