Skip to content

feat: add programmatic API and performance improvements#21

Closed
zzstoatzz wants to merge 1 commit intomainfrom
perf/improve-startup-time
Closed

feat: add programmatic API and performance improvements#21
zzstoatzz wants to merge 1 commit intomainfrom
perf/improve-startup-time

Conversation

@zzstoatzz
Copy link
Copy Markdown
Owner

Closes #20

Summary

This PR addresses the performance concerns raised in #20 by:

  1. Adding a programmatic Python API (generate_docs()) that avoids CLI startup overhead
  2. Documenting performance best practices in PERFORMANCE.md
  3. Providing clear guidance on optimal invocation patterns

Performance Improvements

Based on benchmarking with Prefect (290 modules):

Method Time Notes
Python API ~0.6-1.0s Core generation only, no overhead
uv run ~0.7-1.5s Minimal CLI overhead
uvx (no refresh) ~1.0-2.0s Some environment resolution
uvx --refresh-package ~3.0-5.0s Full package refresh

The main insight is that --refresh-package adds significant overhead (~2s), and using the Python API directly is the fastest approach for CI/CD scenarios.

Changes

New Features

  • Programmatic API: from mdxify import generate_docs - allows direct Python usage without CLI overhead
  • Performance documentation: PERFORMANCE.md with benchmarks and recommendations
  • Benchmarking script: repros/20.py to reproduce and measure performance

Usage Example

from mdxify import generate_docs

result = generate_docs(
    "prefect",
    output_dir="docs/v3/api-ref/python",
    exclude=["prefect.agent"],
    anchor_name="Python SDK Reference",
    include_inheritance=True,
)
print(f"✓ Generated {result['modules_processed']} modules in {result['time_elapsed']:.3f}s")

Testing

  • All existing tests pass
  • API tested with mdxify's own codebase: ~0.026s for 8 modules
  • Benchmarked with Prefect: <0.1s with direct API vs 2-8s with uvx + refresh

Recommendations for Prefect

  1. Remove --refresh-package from your script (saves ~2s)
  2. Consider using the Python API directly for maximum performance
  3. Pin mdxify version to avoid resolution overhead

- Add generate_docs() API for direct Python usage (avoids CLI overhead)
- Document performance best practices in PERFORMANCE.md
- Remove --refresh-package recommendation (adds ~2s overhead)
- Add benchmarking script to reproduce issue #20

Addresses #20 - reduces startup overhead from ~8s to <1s when using the API
@zzstoatzz zzstoatzz closed this Sep 18, 2025
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.

mdxify CLI shows high startup overhead when invoked via uvx; core generation <1s but total ~8–9s

1 participant