Skip to content

Conversation

exrhizo
Copy link

@exrhizo exrhizo commented Jun 17, 2025

Hello Leland,

How do you feel about doing something like this?

pynndescent is adding ~5 seconds on my m1 mac from import when not using umap yet, only importing it for types.

I used py-spy to clarify that most of the umap import time is from, if you like I can message you the json and how to web inspect it.

This helps my developer experience, and it adds some complexity.

Lazy Import Implementation:

  • Replaced direct imports of NNDescent, pynn_named_distances, and pynn_sparse_named_distances with lazy
    loading
  • Created _lazy_import_pynndescent() function that imports these modules only when needed
  • Updated all 8 usage locations in the code to use the lazy import function

@lmcinnes
Copy link
Owner

This is potentially useful, although it does result in longer runtimes for umap as the lazy loading occurs at runtime. This may be a little unexpected for some users. Let me think about this and see if I can work out what the right trade-off is here.

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