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

importing tqdm.auto is very slow due to ipython completion initialization #709

Closed
3 tasks done
jamescasbon opened this issue Apr 8, 2019 · 1 comment · Fixed by #955 or #993
Closed
3 tasks done

importing tqdm.auto is very slow due to ipython completion initialization #709

jamescasbon opened this issue Apr 8, 2019 · 1 comment · Fixed by #955 or #993

Comments

@jamescasbon
Copy link

  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)
$ cat i.py                                                                                                               
from tqdm.auto import trange

 $ python -m cProfile -o istats i.py
$ python -m pstats istats                                                                                                 (tge)  (2s 833ms)  
Welcome to the profile statistics browser.
istats% sort time 
istats% stats 10
Mon Apr  8 09:13:08 2019    istats

         2604401 function calls (2598194 primitive calls) in 2.625 seconds

   Ordered by: internal time
   List reduced from 3049 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    1.311    1.311    2.066    2.066 /home/james/.conda/envs/tge/lib/python3.6/site-packages/IPython/core/completer.py:103(<module>)
  1114112    0.412    0.000    0.412    0.000 {built-in method unicodedata.name}
  1114613    0.228    0.000    0.228    0.000 {built-in method builtins.chr}
      492    0.080    0.000    0.080    0.000 {built-in method marshal.loads}
1492/1489    0.045    0.000    0.171    0.000 {built-in method builtins.__build_class__}
    647/1    0.026    0.000    2.626    2.626 {built-in method builtins.exec}
     5616    0.022    0.000    0.037    0.000 <frozen importlib._bootstrap_external>:57(_path_join)
   134990    0.020    0.000    0.020    0.000 {method 'append' of 'list' objects}
     2396    0.020    0.000    0.020    0.000 {built-in method posix.stat}
      808    0.020    0.000    0.020    0.000 {built-in method __new__ of type object at 0x5629e0adae00}
@jamescasbon
Copy link
Author

In [3]: tqdm.version
Out[3]: '4.31.1'

lpsinger added a commit to lpsinger/tqdm that referenced this issue Apr 29, 2020
In tqdm.auto, look for `IPython` in `sys.modules` rather than
explicitly importing it. If we are in an IPython notebook, then
IPython will have already been imported. If we are not in an
IPython notebook, then importing IPython will take almost half a
second.

Here are import times on a 2018 MacBook Pro with an SSD.
Before this patch:

    $ time python -c 'from tqdm.auto import tqdm'

    real     0m0.474s
    user     0m0.278s
    sys      0m0.142s

After this patch:

    $ time python -c 'from tqdm.auto import tqdm'

    real    0m0.069s
    user    0m0.041s
    sys     0m0.020s

Fixes tqdm#709.
@casperdcl casperdcl mentioned this issue Jun 26, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant