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

Installing jaxtyping makes Pytest slow(er) #220

Open
thejcannon opened this issue Jun 21, 2024 · 3 comments
Open

Installing jaxtyping makes Pytest slow(er) #220

thejcannon opened this issue Jun 21, 2024 · 3 comments

Comments

@thejcannon
Copy link

thejcannon commented Jun 21, 2024

👋

On my machine:

$ time python -c 'import jaxtyping'
python -c 'import jaxtyping'  3.66s user 4.95s system 312% cpu 2.757 total

so, because jaxtyping has the pytest entry point, pytest will load jaxtyping._pytest_plugin which loads jaxtyping which takes 2.75s.

Would you consider putting the pytest-related code under a different tree?

@patrick-kidger
Copy link
Owner

Hey there!
Hmm, I don't think I understand this one. Doing just python -c 'import jaxtyping' shouldn't load pytest at all. In fact with this not even jaxtyping._pytest_plugin is loaded -- this entry point is accessed only by pytest itself.

@thejcannon
Copy link
Author

Right, the two things I was trying to show are:

  • Importing jaxtyping takes 2.75s
  • Because jaxtyping has a pytest hook, pytest loads it, and because the hook points to jaxtyping._pytest_plugin, which is underneath jaxtyping, then jaxtyping/__init__.py is loaded (and he's the slow boy)

So, any pytest invocation is now 2.75s slower.

@patrick-kidger
Copy link
Owner

Ah, hmm. Perhaps it'll be the way that jaxtyping checks if JAX/Equinox are available. I'm speculating here as jaxtyping itself is tiny.

If you can, try benchmarking what happens when {jax, equinox} x {are, aren't} available to be imported and see how that changes things? Maybe we can optimise that somehow.

(FWIW I frequently use jaxtyping + pytest and don't see this kind of multisecond lag, but maybe there's some kind of machine-to-machine variation there.)

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

2 participants