Skip to content

Fix slow CLI start-up - #109

Open
juhoinkinen wants to merge 2 commits into
mainfrom
issue108-CLI-start-up-is-slow
Open

Fix slow CLI start-up#109
juhoinkinen wants to merge 2 commits into
mainfrom
issue108-CLI-start-up-is-slow

Conversation

@juhoinkinen

@juhoinkinen juhoinkinen commented Aug 25, 2026

Copy link
Copy Markdown
Member

Reasons for creating this PR

Execution of the CLI "helper" commands was slow: bibra list-projects, bibra --help and bibra --version all took three seconds. Such slow CLI response is not good.

Link to relevant issue(s), if any

Description of the changes in this PR

Improves CLI startup by deferring expensive backend imports until needed.

  • Adds lazy backend imports and re-exports.
  • Adds a CLI startup-time regression test.

Runtime of bibra --help decreases from 3.14 seconds to 0.30 seconds.

I hoped pytest runs would get faster too, but

  • before two runs took 22 s and 24 s,
  • after two runs took 23 s and 24 s.

so essentially no effect.

Instructions how to test this PR

Time performance before and after this using

for i in $(seq 1 10); do /usr/bin/time -f "%e s" bibra --help >/dev/null; done

Known problems or uncertainties in this PR

Copilot review comments on missing __dir__ method, but I'm not sure if that is a real problem.

Checklist

  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

Disclosure of AI Tool Usage

Please indicate AI use by choosing the most suitable TLP:AI category below and removing the irrelevant categories from the list. AI:ORANGE is the minimum level for merging.

  • 🟡 AI:AMBER AI-generated, fully reviewed line by line. Author can explain every part.

Describe the AI tool(s) you used:

Zoo Code with Qwen3.8-27B

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.79%. Comparing base (2a14380) to head (cfe1b32).

Files with missing lines Patch % Lines
bibra/backend/__init__.py 55.55% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #109      +/-   ##
==========================================
- Coverage   98.50%   97.79%   -0.72%     
==========================================
  Files          13       13              
  Lines         536      543       +7     
==========================================
+ Hits          528      531       +3     
- Misses          8       12       +4     
Flag Coverage Δ
unittests 97.79% <77.77%> (-0.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves CLI startup by deferring expensive backend imports until needed.

Changes:

  • Adds lazy backend imports and re-exports.
  • Adds a CLI startup-time regression test.

Reviewed changes

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

File Description
bibra/config.py Loads backend classes on demand.
bibra/backend/__init__.py Lazily exposes backend APIs.
tests/test_cli.py Enforces a CLI help startup budget.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bibra/backend/__init__.py
Comment on lines +16 to +21
def __getattr__(name: str) -> Any:
"""Import and return a lazily re-exported backend name on access."""
for module, names in _LAZY_MODULES.items():
if name in names:
return getattr(importlib.import_module(module), name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@juhoinkinen
juhoinkinen marked this pull request as ready for review August 25, 2026 13:03
@juhoinkinen juhoinkinen added bug Something isn't working UI labels Aug 25, 2026
@juhoinkinen juhoinkinen added this to the 0.2 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI start-up is slow

3 participants