Skip to content

Speed up CLI help by deferring conversion imports - #2493

Open
Çağdaş Yürekli (cagdasyurekli) wants to merge 1 commit into
microsoft:mainfrom
cagdasyurekli:fix/1438-cli-startup
Open

Çağdaş Yürekli (cagdasyurekli) wants to merge 1 commit into
microsoft:mainfrom
cagdasyurekli:fix/1438-cli-startup

Conversation

@cagdasyurekli

Copy link
Copy Markdown
Contributor

Summary

markitdown --help currently imports the conversion engine and its dependencies before argparse can exit. Defer the engine exports in the package initializer and import MarkItDown in the CLI only after argument parsing and plugin listing.

This keeps the existing package, console entry point, and public Python exports, including wildcard imports and dir(markitdown). Conversion still uses the same engine. No new dependencies are added.

Addresses the startup-performance problem in #1438. The separate argcomplete suggestion is left for a follow-up.

Validation

  • Fresh-interpreter regression tests exercise module and console-entry-point invocation with site-packages disabled: help, version, invalid arguments, and plugin listing.
  • Public API tests check deferred loading, cached exports, wildcard imports, discoverability, and unknown attributes. Existing CLI mocks now target the deferred import's source.
  • Local macOS/Python 3.12 measurements, median of seven fresh processes with all conversion extras installed: python -m markitdown --help 682 ms → 55 ms, --version 675 ms → 55 ms. These are local measurements, not timing assertions in the tests.
  • GITHUB_ACTIONS=true hatch test (Python 3.12): 872 passed, 43 skipped using the repository's CI skip policy and environment-dependent skips.
  • pre-commit run --all-files: passed; git diff --cached --check: passed.

@cagdasyurekli

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (4cc9fa1) and verified on Python 3.12. Resolved the test-consolidation conflict, preserved the service and stdin coverage in test_cli_misc.py, and updated mocks to target the deferred constructor import.

Validation: Black 23.7.0 and git diff --check pass; core pytest: 1059 passed, 57 skipped (repository CI skip policy).

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.

1 participant