3

When I import Pandas or Numpy it's imported instantly, but when I import the library found here

https://github.com/ContextLab/supereeg

It takes a long time to import. I'm updating my own forked copy and would like to reduce the amount of time it takes to load. How do I go about diagnosing why it's taking so long?

pmdaly
  • 1,142
  • 2
  • 21
  • 35
  • I would start by figuring out how long it takes to import each of the modules found in `supereeg/__init__.py` (https://github.com/ContextLab/supereeg/blob/master/supereeg/__init__.py) since that is what's called when you do `import supereeg`. However, at a quick glace, I see that some modules here (like `model.py` call `from .brain import Brain` which might trick you into thinking `model.py` is the problem so you'll have to careful – SyntaxVoid Apr 29 '19 at 22:15
  • Have a look at https://stackoverflow.com/questions/50554374/python-profiling-imports-and-specially-init-is-what-seems-to-take-the-mos/50554426#50554426. Maybe the hints there get you started. – Markus Apr 29 '19 at 22:23
  • How long is long? milliseconds / seconds / minutes? You could start by printing something between every import in the `__init__.py` to get a rough indication of how time is spent. – wovano Apr 29 '19 at 23:03

1 Answers1

2

It probably does expensive initialization on import, which may be considered bad form. Either way, you can find out using Python's built-in profiler:

import cProfiler
cProfiler.run('import supereeg')

The output is not the easiest to parse at all times, but will give you an idea of what's happening. For more info on how to store/sort etc the reports, check the fine docs at https://docs.python.org/3.6/library/profile.html

Fredrik Håård
  • 2,856
  • 1
  • 24
  • 32