Skip to content

Optimize get_command with O(1) lookup dictionary#18

Merged
badMade merged 8 commits into
mainfrom
performance-optimize-get-command-1051592804651335151
Apr 20, 2026
Merged

Optimize get_command with O(1) lookup dictionary#18
badMade merged 8 commits into
mainfrom
performance-optimize-get-command-1051592804651335151

Conversation

@badMade

@badMade badMade commented Apr 16, 2026

Copy link
Copy Markdown
Owner
  • 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).

- 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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/commands.py Outdated
Comment thread src/commands.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 update get_command() to use it.
  • Reformat portions of src/commands.py (string quoting and wrapping).
  • Add several .port_sessions/*.json session 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.

Comment thread src/commands.py Outdated
Comment thread .port_sessions/61ba5d32c11a4224bb560a8f407e4fca.json Outdated
Comment thread .port_sessions/411ef3dc126b43fda86c851515620671.json Outdated
Comment thread .port_sessions/3abe86194be64654a1ed0b4606a57a0e.json Outdated
Comment thread .port_sessions/0d5abcd2ed8446f689dae207ec35254c.json Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
badMade and others added 5 commits April 15, 2026 21:37
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>
…et_command-with-o1-lookup-dictio-r55w0j

Follow-up: remove unused get_commands cwd parameter
@badMade badMade merged commit 2e785b3 into main Apr 20, 2026
4 checks passed
@badMade badMade deleted the performance-optimize-get-command-1051592804651335151 branch April 20, 2026 01:43
@badMade

badMade commented Apr 22, 2026

Copy link
Copy Markdown
Owner Author

@copilot code review

@badMade

badMade commented Apr 22, 2026

Copy link
Copy Markdown
Owner Author

@claude code review

@badMade badMade requested a review from Copilot April 22, 2026 22:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants