Optimize get_command with O(1) lookup dictionary#18
Conversation
- Implement `_get_command_lookup` with `@lru_cache(maxsize=1)`. - Update `get_command` to use dictionary lookup. - Improve average lookup time from ~104us to ~1.6us (~63x speedup). Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request adds several session JSON files and refactors src/commands.py to improve performance and standardize formatting. Key changes include the introduction of a cached lookup dictionary for faster command retrieval and a shift to double-quoted strings. The review feedback highlights an unused cwd parameter in the get_commands function and suggests optimizing the filtering logic within that function into a single-pass generator expression to improve efficiency.
There was a problem hiding this comment.
Pull request overview
This PR optimizes command lookup in the Python reference implementation by replacing a linear scan in get_command() with a cached O(1) dictionary lookup.
Changes:
- Add
_get_command_lookup()cached with@lru_cache(maxsize=1)and updateget_command()to use it. - Reformat portions of
src/commands.py(string quoting and wrapping). - Add several
.port_sessions/*.jsonsession files.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/commands.py | Introduces cached lookup dict to speed up get_command() and applies formatting changes. |
| .port_sessions/61ba5d32c11a4224bb560a8f407e4fca.json | Adds a session artifact JSON file. |
| .port_sessions/411ef3dc126b43fda86c851515620671.json | Adds a session artifact JSON file. |
| .port_sessions/3abe86194be64654a1ed0b4606a57a0e.json | Adds a session artifact JSON file. |
| .port_sessions/0d5abcd2ed8446f689dae207ec35254c.json | Adds a session artifact JSON file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/badMade/claw-code/sessions/010fa4df-27f7-4330-ae41-0e9648558a38 Co-authored-by: badMade <106821302+badMade@users.noreply.github.com>
Agent-Logs-Url: https://github.com/badMade/claw-code/sessions/010fa4df-27f7-4330-ae41-0e9648558a38 Co-authored-by: badMade <106821302+badMade@users.noreply.github.com>
…et_command-with-o1-lookup-dictio-r55w0j Follow-up: remove unused get_commands cwd parameter
|
@copilot code review |
|
@claude code review |
_get_command_lookupwith@lru_cache(maxsize=1).get_commandto use dictionary lookup.