Skip to content

perf: lazy-import vscode_parser and vscode_report in CLI (#890)#891

Merged
microsasa merged 2 commits intomainfrom
fix/890-lazy-vscode-imports-52bbc3ac99b69528
Apr 9, 2026
Merged

perf: lazy-import vscode_parser and vscode_report in CLI (#890)#891
microsasa merged 2 commits intomainfrom
fix/890-lazy-vscode-imports-52bbc3ac99b69528

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Summary

Moves the vscode_parser and vscode_report imports from module level into the vscode() command function so they are only loaded when that subcommand is actually invoked.

Changes

  • src/copilot_usage/cli.py: Removed module-level imports of get_vscode_summary and render_vscode_summary; added local imports inside the vscode() function.
  • tests/copilot_usage/test_vscode_parser.py: Updated two tests that patched copilot_usage.cli.get_vscode_summary to patch copilot_usage.vscode_parser.get_vscode_summary instead, since the import is now local.
  • tests/test_packaging.py: Added test_cli_does_not_import_vscode_modules_at_module_level regression test that verifies neither copilot_usage.vscode_parser nor copilot_usage.vscode_report appear in sys.modules after a clean import of copilot_usage.cli.

Impact

Removes re, stat, types, and the re.compile(...) call from the startup path of all non-vscode subcommands (summary, session, cost, live, interactive mode). Estimated saving: ~3-5 ms per cold invocation.

Closes #890

Generated by Issue Implementer · ● 11M ·

Move the vscode_parser and vscode_report imports from module level into
the vscode() command function so they are only loaded when that
subcommand is actually invoked. This avoids loading re, stat, types, and
executing re.compile() on every CLI invocation.

Update two existing tests that patched the imports at cli module level
to patch at the source module instead.

Add a regression test verifying the lazy-import invariant.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa added the aw Created by agentic workflow label Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 20:21
@microsasa microsasa enabled auto-merge April 9, 2026 20:21
Copy link
Copy Markdown

Copilot AI left a comment

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 reduces CLI startup overhead by deferring VS Code-specific imports until the vscode subcommand is invoked, avoiding importing vscode_parser/vscode_report (and their heavier dependencies) for other subcommands.

Changes:

  • Move vscode_parser / vscode_report imports from copilot_usage.cli module scope into the vscode() command function.
  • Update tests to patch copilot_usage.vscode_parser.get_vscode_summary (since the CLI import is now local).
  • Add a packaging regression test asserting copilot_usage.cli import does not load VS Code modules.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/copilot_usage/cli.py Lazily imports VS Code parser/report only inside the vscode subcommand.
tests/copilot_usage/test_vscode_parser.py Updates mocking target to align with the new lazy import location.
tests/test_packaging.py Adds regression test to ensure cli module import doesn’t import VS Code modules.

@microsasa microsasa added the aw-review-response-attempted Responder has attempted to address review comments label Apr 9, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Commit pushed: bbadb92

Generated by Review Responder

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@microsasa microsasa added the aw-quality-gate-approved Quality gate approved the PR label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Quality Gate: APPROVE

Low-impact performance optimization with good test coverage. Auto-approving for merge.

Evaluated:

  • cli.py: Moves 2 vscode imports from module-level to inside vscode() function — correct lazy-import pattern
  • test_vscode_parser.py: Patch targets updated from copilot_usage.cli.get_vscode_summary to copilot_usage.vscode_parser.get_vscode_summary — correct for local imports
  • test_packaging.py: New regression test verifies vscode modules stay out of sys.modules after importing cli — well-structured with proper cleanup

Impact: LOW — No API/model changes, no new dependencies, behavior unchanged. All 8 CI checks pass.

@microsasa microsasa merged commit aa5a047 into main Apr 9, 2026
8 checks passed
@microsasa microsasa deleted the fix/890-lazy-vscode-imports-52bbc3ac99b69528 branch April 9, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow aw-quality-gate-approved Quality gate approved the PR aw-review-response-attempted Responder has attempted to address review comments

Projects

None yet

2 participants