Skip to content
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

Speedup import time with lazy imports #987

Merged
merged 6 commits into from
Dec 5, 2024
Merged

Conversation

mataton
Copy link
Collaborator

@mataton mataton commented Dec 3, 2024

Addresses #984

The average import time (python -X importtime -c 'import biom') over 7 runs for the current master branch of BIOM is 0.44s. Moving the imports of the required dependencies into their respective functions brings the average import time down to 0.19s, a 2.3x speedup.

Performance of individual functions is only impacted on the first call. For example, the first call to Table.to_dataframe() is 247 microseconds, while all subsequent calls are 180 microseconds. This is due to the module being cached in sys.modules after the first call. The execution time of to_dataframe() without the import statement inside the function is 180 microseconds.

@wasade
Copy link
Member

wasade commented Dec 4, 2024

Thanks @mataton! Would you be able to add a brief note to the change log? I'll merge after

@mataton
Copy link
Collaborator Author

mataton commented Dec 5, 2024

@wasade Thank you for the reminder!

@wasade wasade merged commit 2e6d1c0 into biocore:master Dec 5, 2024
34 checks passed
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.

2 participants