forked from ultraworkers/claw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: Optimize routing engine by caching module search text #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
badMade
wants to merge
2
commits into
main
Choose a base branch
from
bolt-optimize-routing-engine-9159762776880596355
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| ## 2024-03-24 - Python Routing Engine Iteration Performance | ||
| **Learning:** The Python routing engine (`src/runtime.py`) iterates over module properties frequently during the scoring loop. Repeated string allocations and manipulations (`.lower()`) on `PortingModule` properties (like `name`, `source_hint`, `responsibility`) in the inner loop of `_score` causes unnecessary overhead, as these properties are static for a given module. This is specifically highlighted in the context given as a memory hint: "property caching (e.g., using `@functools.cached_property` on `PortingModule` properties like `search_text`) is critical for performance to avoid redundant string allocations and manipulations." | ||
|
|
||
| **Action:** Add a `@functools.cached_property` called `search_text` to the `PortingModule` dataclass that precomputes and lowercases the combined searchable fields. Update `_score` in `src/runtime.py` to use this single precomputed string instead of repeatedly building the `haystacks` list and lowering the fields on every token evaluation. | ||
|
|
||
| ## 2024-04-09 - Rust String Cloning Optimization | ||
| **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. | ||
| **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()`). | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.