question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: faster import

See original GitHub issue

Is your feature request related to a problem? Please describe.

It’s very slow to import sfaira. This includes any use of the command line interface. For example:

$ time sfaira --help
...
sfaira --help  28.27s user 1.04s system 106% cpu 27.624 total
%time import sfaira

Describe the solution you’d like

Faster import of Sfaira by delaying computation of whatever is taking so long.

Additional context

It looks to me like this is mostly coming from this line:

https://github.com/theislab/sfaira/blob/dab9cb3f6d89dc6c6b52f9ce23c9a7e938e4d91b/sfaira/consts/__init__.py#L5

and the subsequent loading of a bunch of ontologies. Here’s the first couple lines of %prun -s cumtime import sfaira for evidence that this is the culprit:

         46387199 function calls (46339180 primitive calls) in 33.690 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      276    0.005    0.000   38.698    0.140 __init__.py:1(<module>)
        7    0.001    0.000   33.802    4.829 __init__.py:2(<module>)
   4477/1    0.029    0.000   33.693   33.693 {built-in method builtins.exec}
   3377/1    0.014    0.000   33.693   33.693 <frozen importlib._bootstrap>:986(_find_and_load)
   3364/1    0.010    0.000   33.693   33.693 <frozen importlib._bootstrap>:956(_find_and_load_unlocked)
   3166/1    0.011    0.000   33.693   33.693 <frozen importlib._bootstrap>:650(_load_unlocked)
   2975/1    0.006    0.000   33.693   33.693 <frozen importlib._bootstrap_external>:842(exec_module)
   5107/1    0.003    0.000   33.693   33.693 <frozen importlib._bootstrap>:211(_call_with_frames_removed)
        1    0.000    0.000   30.572   30.572 ontologies.py:10(__init__)
        6    0.000    0.000   29.722    4.954 base.py:551(__init__)
        6    0.045    0.008   29.722    4.954 base.py:512(__init__)
        6    0.657    0.109   29.677    4.946 read.py:12(read_obo)
        6    1.020    0.170   28.010    4.668 read.py:63(get_sections)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
davidsebfischercommented, Jul 20, 2021

We could keep the OCS constant but only populate it with the intialised ontologies based on a particular function call, sfaira.initialise() for example.

0reactions
Zethsoncommented, Sep 20, 2021

https://github.com/theislab/sfaira/commit/c26c0dbbbcf07cc82169a960a70ea6f88595af64

@davidsebfischer CLI startup is now in the order of 1-2 seconds. Can’t improve it much further as long as TensorFlow is involved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Allow direct import of utils ... - GitHub
[Feature Request] Allow direct import of utils.PlotlyJSONEncoder for faster Dash startup time #2174. anders-kiaer opened this issue on Feb 10, ...
Read more >
Best practices to increase the speed for Next.js apps
Following these best practices will help you take advantage of those features so you can start building faster Next.js applications. Tags: next.
Read more >
[Feature Request] Sketcher: Importing an edge from another ...
Re: [Feature Request] Sketcher: Importing an edge from another body. A couple features that could have made the process a little faster: 2D ......
Read more >
Want Faster HTTP Requests? Use A Session with Python!
It comes with many benefits and lets us access more features within the requests library, the most common and used Python library for...
Read more >
Feature Request: Import Instrument Lists with Exchanges.
Please can I submit a feature request to enable instrument lists to ... but hoping this is an easier/faster to implement request that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found