You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Learning:** In Rust, building lists of string parts for joining (e.g., `vec![string1.clone(), string2.clone()].join(" ")`) is a common pattern that can lead to unnecessary heap allocations. This codebase frequently does this when formatting reports. When the source values are already `String`s, borrowing them as `&str` and pushing them to a `Vec<&str>` before calling `.join()` entirely avoids these intermediate heap allocations. Additionally, calling `.to_string()` on static string slices just to appease a `Vec<String>` is wasteful when `Vec<&str>` works perfectly.
3
+
**Action:** When constructing strings from parts using `Vec` and `.join()`, look for opportunities to use a `Vec<&str>` populated with borrowed string slices (`.as_str()`) instead of a `Vec<String>` populated with cloned strings (`.clone()`).
1
4
2
5
## 2024-05-18 - Caching Python Dataclass Properties for Routing Performance
3
6
**Learning:** In the Python port of the agent (`src/runtime.py`), the `PortRuntime._score` method processes routing modules on every input prompt. Repeatedly constructing a lowercase `haystacks` list in this hot loop causes redundant string allocations and `.lower()` calls, creating a measurable performance drag.
4
-
**Action:** Use `@functools.cached_property` on the `PortingModule` (which is a `@dataclass(frozen=True)`) to lazily compute and cache a single search text string combining name, source hint, and responsibility, separated by `\0` null bytes to prevent overlapping field matches. Python 3.12+ supports `cached_property`on frozen dataclasses, allowing us to use this to avoid repeated string computations.
7
+
**Action:** Use `@functools.cached_property` on the `PortingModule` (which is a `@dataclass(frozen=True)`) to lazily compute and cache a single search text string combining name, source hint, and responsibility, separated by `\0` null bytes to prevent overlapping field matches. This works here because `PortingModule` instances have a `__dict__` available for `cached_property`caching (that is, they are not slotted), allowing us to avoid repeated string computations.
0 commit comments