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

Break navis into submodules #53

Open
schlegelp opened this issue Aug 21, 2021 · 0 comments
Open

Break navis into submodules #53

schlegelp opened this issue Aug 21, 2021 · 0 comments

Comments

@schlegelp
Copy link
Collaborator

schlegelp commented Aug 21, 2021

This is just to get a discussion starting (@clbarnes):

Currently most functions in navis are automatically imported at top-level.

Pros:

  • convenient because most functions are easy to call via navis.{function}

Cons:

  • importing navis is slow
  • for a many analyses one doesn't even need all functions
  • crowded namespace
  • any missing dependency breaks the whole package

My preferred way of improving the situation would be to break navis into functionalities and only the core functions are imported at top-level. It might be worth doing some profiling to see where the actual bottlenecks are.

What I would consider core functionality:

  1. All neuron data models (i.e. navis.core)
  2. The above requires navis.graph
  3. navis.converters to move between neuron representations

In practice there aren't all that many modules that could be easily decoupled without re-organizing:

  1. navis.nbl(NBLAST) is independent
  2. navis.morpho and navis.plotting could be decoupled using lazy imports in the core modules
  3. navis.tranforms and navis.data are also independent but probably won't save much time on import
  4. navis.intersection could be decoupled

Other alternatives:

  • make imports conditional on some environment flag. For example backend user could set NAVIS_CORE=TRUE and navis only imports core functions at top level while for all other users the experience doesn't change
  • make expensive imports (like Matplotlib, VisPy, etc) lazy

I had a quick crack at the imports using python -X importtime and pasting the results of import navis into this website for visualisation:

importtime

The top 100 worst imports (if I understand the output correctly) are these:

 time[s]                              name
    6.02                             navis
    5.46                navis.connectivity
    5.45        navis.connectivity.predict
    4.42                        navis.core
    3.73                navis.core.volumes
    2.91                       navis.utils
    1.90             navis.utils.iterables
    1.08                      navis.config
    0.98                  navis.utils.misc
    0.87                            pandas
    0.86                  navis.transforms
    0.83        navis.transforms.templates
    0.82                              pint
    0.81                           trimesh
    0.80                      pint.context
    0.80                  pint.definitions
    0.79                   pint.converters
    0.78                       pint.compat
    0.77                            xarray
    0.66                     tqdm.notebook
    0.65                        ipywidgets
    0.65                     pkg_resources
    0.58                      trimesh.base
    0.55                  navis.clustering
    0.55          navis.clustering.cluster
    0.55                    navis.plotting
    0.50                           IPython
    0.43                 matplotlib.pyplot
    0.42            IPython.terminal.embed
    0.36                     trimesh.poses
    0.36                          networkx
    0.34                   navis.core.base
    0.32                 navis.plotting.dd
    0.32         navis.plotting.plot_utils
    0.32             vispy.util.transforms
    0.32                        vispy.util
    0.32                             vispy
    0.31                        vispy.util
    0.30                  vispy.util.fonts
    0.30          vispy.util.fonts._triage
    0.30          vispy.util.fonts._quartz
    0.30                 vispy.ext.cocoapy
    0.30                             numpy
    0.30                   pandas.core.api
    0.29                           seaborn
    0.28                         OpenGL.GL
    0.25 IPython.terminal.interactiveshell
    0.25               networkx.generators
    0.24                     seaborn.rcmod
    0.24                  seaborn.palettes
    0.23                     seaborn.utils
    0.23                       scipy.stats
    0.22               navis.core.skeleton
    0.22                navis.plotting.ddd
    0.22                 scipy.stats.stats
    0.21  networkx.generators.intersection
    0.20               networkx.algorithms
    0.20             trimesh.exchange.load
    0.20         scipy.stats.distributions
    0.18       navis.plotting.vispy.viewer
    0.18              navis.plotting.vispy
    0.18                     pandas.compat
    0.17               matplotlib.colorbar
    0.16                       trimesh.ray
    0.16                     scipy.spatial
    0.16          trimesh.ray.ray_triangle
    0.16              trimesh.ray.ray_util
    0.16                ipywidgets.widgets
    0.16                        numpy.core
    0.15                    trimesh.bounds
    0.15               pandas.core.groupby
    0.15       pandas.core.groupby.generic
    0.15    scipy.stats._continuous_distns
    0.13                pandas.core.arrays
    0.13       navis.plotting.vispy.viewer
    0.13                   trimesh.nsphere
    0.13                    scipy.optimize
    0.13                       vispy.scene
    0.12             navis.core.core_utils
    0.12                   navis.core.mesh
    0.12                          requests
    0.12                matplotlib.contour
    0.12            pathos.multiprocessing
    0.12                            pathos
    0.11                 pandas.core.frame
    0.11          navis.transforms.factory
    0.11         IPython.terminal.debugger
    0.11             trimesh.exchange.misc
    0.11                  navis.conversion
    0.11         ipywidgets.widgets.widget
    0.11                            meshio
    0.11               pandas.compat.numpy
    0.11            IPython.core.completer
    0.11                    ipykernel.comm
    0.11               pandas.util.version
    0.11          navis.conversion.meshing
    0.11               vispy.scene.visuals
    0.11                      pathos.pools
    0.11              prompt_toolkit.enums
    0.11                    prompt_toolkit

Most of these navis doesn't directly import but for example pint is unfortunately very expensive.

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

1 participant