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

ENH: delay expensive imports #4265

Merged

Conversation

neutrinoceros
Copy link
Member

@neutrinoceros neutrinoceros commented Dec 24, 2022

PR Summary

Reduces yt's startup time by ~30% (from 1.57s to 1.07s on my machine, averaged over 100 runs)

Measured with this simple script

from time import monotonic_ns

tstart = monotonic_ns()
import yt
tstop = monotonic_ns()
print(f"{(tstop-tstart)/1e9:.3f}")                                                                      

diff

@neutrinoceros neutrinoceros added enhancement Making something better performance labels Dec 24, 2022
@neutrinoceros neutrinoceros added this to the 4.2.0 milestone Dec 24, 2022
@neutrinoceros neutrinoceros force-pushed the delay_expensive_type_only_imports branch from a40c575 to 8863b83 Compare December 24, 2022 12:14
@neutrinoceros
Copy link
Member Author

Getting some errors at collection time in minimal env tests. I don't immediately get what's happening so I'll switch to draft for now.

@neutrinoceros neutrinoceros marked this pull request as draft December 24, 2022 14:07
@neutrinoceros neutrinoceros force-pushed the delay_expensive_type_only_imports branch from 44c05c3 to 5e20545 Compare December 24, 2022 14:59
@neutrinoceros neutrinoceros marked this pull request as ready for review December 24, 2022 15:50
@neutrinoceros neutrinoceros changed the title ENH: delay expensive, type-check-only, matplotlib imports ENH: delay expensive imports Dec 24, 2022
@neutrinoceros
Copy link
Member Author

I found that urllib.request, which is probably never actually used within yt, costs about 1% (and 2.5% with incoming improvements in our other dependencies) of startup overhead. It's definitely in the realm of fine tuning but it's basically free to implement, so I went for it too.

@neutrinoceros neutrinoceros force-pushed the delay_expensive_type_only_imports branch from 21925fd to 8f86151 Compare December 24, 2022 18:58
@@ -23,6 +21,10 @@
validate_image_name,
)

if TYPE_CHECKING:
Copy link
Member

Choose a reason for hiding this comment

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

this is a good thing to know about!

@matthewturk matthewturk merged commit 20a7957 into yt-project:main Dec 28, 2022
@neutrinoceros neutrinoceros deleted the delay_expensive_type_only_imports branch December 28, 2022 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making something better performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants