Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm Django Debugging is really slow

I have a moderate size website but it takes about 30 seconds for PyCharm to start Runserver and be ready to run the app. If I "Run" the app instead of "Debugging" it will only take about 3 seconds to start.

What are some of the things I can do speed up the code change and debugging cycle. I am using a decent MBP with 16Gb of RAM. So hardware is not the issue.

I have excluded /media files from the project. I don't any other large number of files that will cause indexing problems I am using both Postgres and Mongo db. I am running Django 1.7 + a dozen of packages like:

dj-static==0.0.6
django-annoying==0.8.1
django-appconf==1.0.1
django-bootstrap-form==3.2
django-bootstrap-pagination==1.5.1
django-compressor==1.5
django-extensions==1.5.5
django-filter==0.10.0                              
django-guardian==1.2.5
django-storages-redux==1.2.3
django-widget-tweaks==1.3
djangorestframework==3.1.2                        
django-jinja==1.4.1

This is debug output:

/Users/user1/.virtualenvs/env-test/bin/python "/Applications/PyCharm 4.5 EAP.app/Contents/helpers/pydev/pydevd.py" --multiproc --save-signatures --client 127.0.0.1 --port 64097 --file /Users/user1/gitroot/website1/manage.py runserver 0.0.0.0:8000 --verbosity 2
Connected to pydev debugger (build 141.1245)
pydev debugger: process 63926 is connecting

pydev debugger: process 63954 is connecting

Performing system checks...

System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
June 03, 2015 - 09:08:52
Django version 1.7.7, using settings 'myproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

UPDATE: Since this post Pycharm has the ability to use Cython as the interpreter. I think that has improved things somewhat. I also moved to use Runserverplus which I think runs faster.

like image 909
David Dehghan Avatar asked Jun 03 '15 16:06

David Dehghan


People also ask

Is debug mode slower Python?

If your code does some high performance computations, Debugger will be at least 3 times slower than usual Run.

Why is IntelliJ debugging so slow?

Remove breakpoints off your method and use them inside the method as that can cause your debug to take a very long time. Try running IntelliJ as admin. I had this issue at work where debugging was extremely slow and running as admin actually made it a lot faster.

What does Django debug true do?

The debug mode (DEBUG=True) is turned on by default in the Django framework. It provides a detailed traceback with the local variables to find out the error with the line numbers. The error can be triggered from the view page by setting the value of assert to False in the view file.


4 Answers

Well, the debugger is just slow and there is not much you can do about it. Just don't use the debugger unless you absolutely need it (i.e. you are troubleshooting a particularly elusive bug).

I can think of only one thing that may speed up the PyCharm's debugger and that is to turn off the "Collect run-time types information for code insight" setting (located under File > Settings > Build, Execution, Deployment > Python Debugger).

like image 73
Spc_555 Avatar answered Sep 28 '22 20:09

Spc_555


For me the issue improved when I remembered I had enabled the debugger to collect type information.

  • Hit Ctrl-Shift-A or search under Settings > Build, Execution, Deployment > Python Debugger for collect run-time types information for code insight

  • Un-check the box and hit apply

  • See if this helps

I run PyCharm Community 5.0.1

like image 23
petroslamb Avatar answered Sep 28 '22 21:09

petroslamb


I noticed the original poster's debug output doesn't include the message about cython. I came to this post because I couldn't figure out why my pycharm debug was so slow, but later I realized a suggestion for speeding up the debugger is right here in my debug output.

"<some-path-to-python>/python" "/Applications/PyCharm.app/Contents/helpers/pydev/setup_cython.py" build_ext --inplace

I hope folks have tried that. I guess this answer is for the non-output readers of the world.

like image 32
winklebort Avatar answered Sep 28 '22 20:09

winklebort


Need to experiment on these, taken from Jetbrain blog:

  1. delete all breakpoints
  2. turn off tracing exceptions
  3. no runtime type insights

But also look at disabling Django model checking etc to speed up.

I'v used a patch to speed up test cases, 10x faster to run. So, if you do TDD, functions are less heavier than views. It let you resolve bug quickly.

like image 37
CodeFarmer Avatar answered Sep 28 '22 22:09

CodeFarmer