Faster debugger in PyCharm 5.1
The first EAP for PyCharm 5.1 was released last week, with lots of enticing features. Here’s one that jumps out for long-time users: “Debugger performance improvements”. Let’s take a look at this in a little more depth, then provide some of the back story.
Imagine we’re debugging a semi-large code base with PyCharm 5.0.4. If we set a breakpoint and time how long it takes to get there, it measures out as 12 seconds:
In PyCharm 5.1, the debugger performance has improved, especially for large code bases. Let’s give the same scenario a try:
Almost 3.5 seconds of improvement on OS X.
Wouldn’t it be great to get a couple more seconds? And now comes the real story: the new debugger has some performance improvements implemented in Cython. On OS X and Linux we need to install them manually, as the debugger console message helpfully tells us:
Windows users get these Python speedups pre-bundled. Let’s install them on OS X by copying the text above after “Debugger speedups using Cython not found. Run…”:
That is, we’re running:
env27/bin/python /Applications/PyCharm\ 5.1\ EAP.app/Contents/helpers/pydev/setup_cython.py build_ext --inplace
…using the Python in this project’s virtual environment, just to make sure we have the correct Python version. Once more, let’s measure the time to get to the breakpoint:
5.7 seconds! That’s a meaningful difference. As stated by the developers, the debugger is 40% faster in the general case and over 130% faster when you have the Cython modules compiled and installed. Again, if you are on Windows, you don’t need to do anything — you will get these improvements automatically for Python 2.7, Python 3.4, and Python 3.5 interpreters.
On OS X and Linux, you need to do a one-time compilation using any Python on your system matching the Python version you need, as shown in the screenshot above. For example, if you use Python 2.7 and Python 3.4, you need to run the Cython speedups with an interpreter matching those two versions. Each time you run it, a compiled speedup will be saved in your PyCharm application, for that Python version. For example, on my system, this was created:
/Applications/PyCharm 5.1 EAP.app/Contents/helpers/pydev/build/lib.macosx-10.11-x86_64-2.7/_pydevd_bundle/pydevd_cython.so
Note the “-2.7” in the directory name. Also, note that you don’t have to do this with your virtual environment’s Python, but it certainly makes sense to do so, as you’ll be sure to match the version. You don’t have to do this once for every Python 2.7 virtual environment, as these speedups aren’t stored in the virtual environment. They are stored inside PyCharm’s pydevd helper.
Now, on to the backstory. As explained in the blog post announcing the 5.1 EAP, JetBrains joined efforts with PyDev, helping sponsor the work on pydevd which is shared by the two projects. Both projects require a sophisticated debugger backend and previously merged their work. This performance improvement is another step forward in the collaboration.
If you debug a large code base, give this EAP a try with the Cython speedups and post a comment letting us know your results. We expect performance improvements to be higher for larger code bases.
PyCharm Team
The Drive to Develop