Skip to content

Importing the DSPy library is very time consuming, what is this due to?Is it possible to optimize this problem? #8252

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

Open
17Reset opened this issue May 21, 2025 · 4 comments

Comments

@17Reset
Copy link

17Reset commented May 21, 2025

import time

start_time = time.time()
import dspy
print(f"load dspy time: {time.time() - start_time} s")
load dspy time: 5.986269474029541 s
@estsauver
Copy link
Contributor

The long import time is mostly due to DSPy’s design choice to expose many features at the top level. The init.py file imports numerous subpackages and re‑exports their symbols so users can simply write import dspy and immediately access predictors, retrievers, adapters, and evaluation utilities. These subpackages import heavy dependencies—such as litellm, regex, numpy, and pandas—as soon as they’re loaded. This eager loading ensures everything is ready to use but means that importing DSPy pulls in a large dependency graph, making startup slower than a lightweight library.

@chenmoneygithub
Copy link
Collaborator

@17Reset Thanks for reporting the issue! We are aware of this, and in an effort of shrinking the memory/time consumption at importing time. In our incoming DSPy 3.0 release, we will ensure this runs much faster.

@17Reset
Copy link
Author

17Reset commented May 22, 2025

Thanks for clearing up the confusion, and look for a better performing DSPy to arrive soon!

@TomeHirata
Copy link
Collaborator

Yes, we'll reduce dependencies and packages imported with import dspy in DSPy 3.0.

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

No branches or pull requests

4 participants