-
Notifications
You must be signed in to change notification settings - Fork 156
Speed up bm --version startup #534
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task in 1m 50s —— View job PR Review: Speed up bm --version startupReviewing this performance optimization PR against our team checklist. SummaryThis PR successfully optimizes Key Changes:
Code Quality & Standards✅ Follows Basic Memory's coding conventions
✅ Python 3.12+ conventions followed
✅ FastAPI and Typer conventions followed
✅ No commented-out code blocks
Testing & Documentation✅ Regression tests added
Recommendation: While the subprocess tests verify the behavior works correctly, consider adding a unit test for # tests/cli/test_cli_version_fastpath.py
from basic_memory.cli.main import _version_flag_present
def test_version_flag_detection():
assert _version_flag_present(["--version"])
assert _version_flag_present(["-v"])
assert _version_flag_present(["--help", "--version"])
assert not _version_flag_present(["--help"])
assert not _version_flag_present([])However, since the function is trivial and covered by integration tests, the current ✅ Documentation updated appropriately
Basic Memory Architecture✅ MCP architecture preserved
✅ Local-first architecture maintained
✅ Performance optimization aligns with project goals
Security & Performance✅ No security issues
✅ Performance improvement verified
✅ No sensitive data concerns
Compatibility✅ Cross-platform compatible
✅ No emoji/unicode issues
Detailed Code Reviewsrc/basic_memory/cli/main.pyLines 8-9: Helper function def _version_flag_present(argv: list[str]) -> bool:
return any(flag in argv for flag in ("--version", "-v"))✅ Clean implementation, handles both long and short forms Lines 12-25: Conditional imports if not _version_flag_present(sys.argv[1:]):
# Register commands only when not short-circuiting for --version
from basic_memory.cli.commands import ...✅ Comment clearly explains the optimization src/basic_memory/cli/commands/mcp.pyLines 1-10: Import reordering Lines 42-47: Deferred imports # Deferred imports to avoid heavy startup cost for unrelated CLI commands
from basic_memory.mcp.server import mcp as mcp_server # pragma: no cover
# Import mcp tools/prompts to register them with the server
import basic_memory.mcp.tools # noqa: F401 # pragma: no cover
import basic_memory.mcp.prompts # noqa: F401 # pragma: no cover✅ Comment explains the "why" (literate programming style) SuggestionsMinor: Consider early return in app_callbackIn Documentation: Link to performance benchmarksConsider adding a comment in # Trigger: --version or -v flag present in CLI args
# Why: avoid loading ~16 MCP tools and their dependencies (~500ms saved)
# Outcome: defers command registration, faster version check
if not _version_flag_present(sys.argv[1:]):This follows the "Decision Point Comments" pattern from CLAUDE.md. Final ChecklistCode Quality & Standards
Testing & Documentation
Basic Memory Architecture
Security & Performance
Compatibility
Recommendation: APPROVE ✅This PR is well-implemented, properly tested, and achieves its performance optimization goal without introducing technical debt or breaking changes. The deferred import pattern is appropriate for CLI commands and follows Python best practices. No blocking issues found. The code is ready to merge after approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9844fcb360
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _version_flag_present(argv: list[str]) -> bool: | ||
| return any(flag in argv for flag in ("--version", "-v")) | ||
|
|
||
|
|
||
| if not _version_flag_present(sys.argv[1:]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t treat every -v as a global version flag
The new _version_flag_present gate treats any -v anywhere in argv as --version, which skips importing all subcommands. That breaks normal invocations like bm status -v or bm project -v where -v is a per-command verbose flag (see status.py/project.py options), because the command modules never register and Typer will report “No such command.” This regression only happens when a subcommand uses -v, so the fix should scope the version check to top-level flags (e.g., only when -v/--version appears before any subcommand).
Useful? React with 👍 / 👎.
Summary
Testing