148

I'm a big fan of PyCharm by JetBrains but I do run into some issues that I thought maybe I'll ask here about.

  1. It hangs unexpectedly and this happens often. Overall, its a little bit slow for my taste and I would love some tips on how to increase the performance of the IDE
  2. Often when I open a project PyCharm seems to flag all the built-ins as Unresolved Reference warnings. things like open(), str(), etc. as well as some of the modules I import such as sys (these are the most common offenders :) ).

The only way I am able to fix (2) is by going to PyCharm -> Preferences -> Python Interpreters -> Paths -> Reload List of Paths but I have to do this often enough to warrant asking about a more permanent fix.

My configuration: Mac OSX Lion running on MacBook Pro (mid 2010) with 8GB RAM

Now look, I understand that diagnosing things like these is difficult without any sort of snapshot or more information about what is going on, but I am simply asking if anyone has ran into these issues before and if so, how did these get resolved?

P.S. I have also contacted JetBrains regarding these issues, but honestly I tend to find nice solutions to common problems here and I thought I might as well ask

bad_coder
  • 11,289
  • 20
  • 44
  • 72
mlnyc
  • 2,636
  • 2
  • 24
  • 29
  • My PyCharm was running very slow (hangs for a few seconds very often) when the console had a lot of lines. => I removed some prints and it went back to normal – Vincent J Oct 13 '15 at 10:32
  • 1
    See also: https://stackoverflow.com/questions/38242978/how-to-make-pycharm-faster-lighter/45775946#45775946 – Stephen Aug 20 '17 at 01:38

12 Answers12

179

1. Change the inspection level

Current PyCharm versions allows you to change the type of static code analysis it performs, and also features a Power/CPU Saving feature (Click on the icon at the bottom right, next to the lock):

enter image description here

2. Change indexed directories
Exclude directories from being indexed which are set in the project paths but not actually required to be searched and indexed. Press ALT+CTRL+S and search for project.

3. Do memory sweeps
There is another interesting feature:

Go into the settings (File/Settings) and search for memory. In IDE Settings>Appearance -> tick Show memory indicator. A memory bar will be shown at the bottom right corner (see the picture below). Click this bar to run a garbage collection / memory sweep.

enter image description here

SamCyanide
  • 323
  • 4
  • 15
Lorenz Lo Sauer
  • 23,698
  • 16
  • 85
  • 87
  • 10
    Shouldn't such things run automatically once in a while? – Berry Tsakala Feb 06 '14 at 10:06
  • @BerryTsakala true and it does usually work quite well. I am not familiar with Jetbrains GC improvements, however here is a pretty good sum-up of 'plain vanilla' GC in JAVA: http://javarevisited.blogspot.com.es/2011/04/garbage-collection-in-java.html Cheers! – Lorenz Lo Sauer Apr 11 '14 at 08:51
  • 17
    ctrl+alt+s -> settings – mateuszb Jul 23 '14 at 18:12
  • 2
    I would also disable any plugins you are not using. Double shift and search for "plugins" and untick all those you don't need. – Steve Rossiter Aug 29 '15 at 13:18
  • 1
    Turning off Plugins helps in fast startup. – Ciasto piekarz Dec 06 '15 at 13:19
  • Point #1 helped a lot for me, I was about to uninstall and go back to Sublime 3 because i couldn't scroll smoothly, but now PyCharms is usable. – wilblack Feb 11 '16 at 19:16
  • Just want to share that Point #2 works, please excluded your ".git" folder as well ... – Steven Du Apr 05 '16 at 06:01
  • In OSX, on PyCharm CE 2016.3.2, #1 didn't exist, and for #2 and #3 those shortcuts of course won't work, but I did a CMD-(left) Shift-A, which brings up an 'options search' dialogue to help me find these. For me, having project roots as my whole home directory caused some serious slowdown issues. Thanks for writing this. – Emmel Feb 24 '17 at 20:22
  • is there is a way to increase heap size? – Yuda Prawira May 08 '17 at 10:15
  • I have done most of the solutions, changing the inspection level , solution 2 and 3 , even i remove some plugins but my **pycharm** , still freezes when am typing , i am using WIn10 on aa PC of 8gb RAM and i core5 , initially the IDE was working very well , now it continues slowing. – Lutaaya Huzaifah Idris Mar 07 '18 at 08:16
  • I had the biggest problems in auto format (I practically issue ctrl+alt+l every two or three lines of code) and the problem arose after generating some very big sources; Solution #2 solved the problem: First I excluded those generated big sources then performed a clear cache and restart and worked again fine. Those big sources are definition of python very large arrays on source (data directly in the source) for test/trial purpose (not for production) so it was fine to exclude them from indexing. – Ettore Galli May 29 '18 at 07:55
35

Every performance problem with PyCharm is unique; a solution that helps one person will not work for another. Therefore, the only proper way to fix your specific performance problem is by capturing the CPU profiler snapshot as described in this document and sending it to the PyCharm support team, either by submitting a ticket or directly into the issue tracker.

After the CPU snapshot is analyzed, the PyCharm team will work on a fix and release a new version which will (hopefully) not be affected by this specific performance problem. The team may also suggest you some configuration changes or workaround to remedy the problem based on the analysis of the provided data.

All the other "solutions" (like enabling Power Save mode and changing the highlighting level) will hide the real problems that should be fixed.

David Beauchemin
  • 231
  • 1
  • 2
  • 12
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 2
    @CrazyCoder is there anything we can do if PyCharm starts consuming CPU cycles? Previously it would happen while a specific Python file was focused in the editor, but this was fixed with version 5. But now with version 2016.1.2 the IDE seems to randomly start using >50% even with all editor files closed and nothing running and in Power Save mode, and it carries on indefinitely until I close PyCharm, and soon starts again on resuming it. Any idea? Memory is about 200MB (of 725). I'm running OS X 10.11.3, PyCharm build #PY-145.844. This is a big issue for me as I live in a place with power cuts. – Chris Apr 28 '16 at 09:04
  • To clarify, I mean to figure out what PyCharm is stuck on processing. I'm posting as a comment as I don't think PyCharm needs lots of bad SO questions, and I haven't had much luck with issues that aren't obvious bugs on the support process. My fan just stopped for a few hours, and usage went back down to 5%, but it just shot up again. I didn't do anything in PyCharm. – Chris Apr 28 '16 at 12:06
  • 1
    @Chris please refer to https://intellij-support.jetbrains.com/hc/articles/207241235 – CrazyCoder Apr 28 '16 at 16:52
  • It is related to iPython running in the Python Console, possibly trying to run Django while it had errors. Removing ipython from my virtual environment seems to have solved the issue - so far the non-ipython console is not causing the same issue. So nothing to do with PyCharm. Thanks @CrazyCoder for the follow-up. – Chris May 04 '16 at 16:30
  • I'm mistaken, it is now happening without iPython running. I've posted a bug report [here](https://youtrack.jetbrains.com/issue/PY-19464) thanks. – Chris May 09 '16 at 22:20
  • 4
    "Every performance problem with PyCharm is unique" in other words, PyCharm is unfixable :-( To the contrary, a common non-unique problem seems to be a large data folder in the project that should be exclude from inspection. – jolvi Jan 30 '19 at 13:22
  • @jolvi thanks for the feedback, there are certainly common cases for the performance problems, but most of them are still different and it would be better to report them to JetBrains with the CPU snapshots and other details so that they can be fixed properly and no workarounds would be required in the future. For example, it may be specific to the file types and data you have in that folder and the snapshot would help to catch the bug and fix it. – CrazyCoder Jan 30 '19 at 21:08
16

Well Lorenz Lo Sauer already have a good question for this. but if you want to resolve this problem through the Pycharm Tuning (without turning off Pycharm code inspection). you can tuning the heap size as you need. since I prefer to use increasing Heap Size solution for slow running Pycharm Application.

You can tune up Heap Size by editing pycharm.exe.vmoptions file. and pycharm64.exe.vmoptions for 64bit application. and then edit -Xmx and -Xms value on it.

So I allocate 2048m for xmx and xms value (which is 2GB) for my Pycharm Heap Size. Here it is My Configuration. I have 8GB memory so I had set it up with this setting:

-server
-Xms2048m
-Xmx2048m
-XX:MaxPermSize=2048m
-XX:ReservedCodeCacheSize=2048m

save the setting, and restart IDE. And I enable "Show memory indicator" in settings->Appearance & Behavior->Appearance. to see it in action :

Pycharm slow, slow typing, increase Pycharm Heap Size

and Pycharm is quick and running fine now.

Reference : https://www.jetbrains.com/help/pycharm/2017.1/tuning-pycharm.html#d176794e266

Yuda Prawira
  • 12,075
  • 10
  • 46
  • 54
  • 1
    Perfect :) Restarting the IDE should be mentioned. – Appyx Mar 07 '19 at 15:46
  • 1
    This is the best answer (see JMJ's answer below which gives an easy way to edit it). PyCharm's default memory max of 2GB is a bit low for many users I think. – Stephen May 05 '20 at 16:39
  • I couldn't find "Show memory indicator" in settings->Appearance & Behavior->Appearance on PyCharm 2021.2.1 Professional Edition – Homero Esmeraldo Jun 29 '22 at 05:43
  • 1
    @HomeroEsmeraldo right click on the bottom of the window and select "memory indicator" (2023.1.2) – FlipMcF Jun 06 '23 at 16:04
16

In my case, the problem was a folder in the project directory containing 300k+ files totaling 11Gb. This was just a temporary folder with images results of some computation. After moving this folder out of the project structure, the slowness disappeared. I hope this can help someone, please check your project structure to see if there is anything that is not necessary.

iteal
  • 441
  • 7
  • 14
  • 5
    This! If you want to keep the folder in the Project Directory, exclude it from indexing by: right click on the folder you want to exclude, 'Mark Directory as' -> 'Excluded' – dtadres Jul 20 '19 at 16:42
  • 1
    This was my exact problem, too many images being stored alongside my code, and by Marking the directory as excluded the slowness/stuttering went away. – IntegrateThis Oct 21 '21 at 01:53
  • This, i run `du -sh * * | sort -h` to see whats the largest files in my project, make sure to exclude those if its not code because it slows the app down heaps if its something big. – lee penkman Jun 30 '23 at 01:05
  • This answer still applies in 2023. Marking directory full of json files as excluded made a HUGE difference. – Nick Jul 29 '23 at 18:49
6

It is super easy by changing the heap size as it was mentioned. Just easily by going to Pycharm HELP -> Edit custom VM option ... and change it to:

-Xms2048m
-Xmx2048m
JMJ
  • 2,034
  • 2
  • 16
  • 17
4

Regarding the freezing issue, we found this occurred when processing CSV files with at least one extremely long line.

To reproduce:

[print(x) for x in (['A' * 54790] + (['a' * 1421] * 10))]

However, it appears to have been fixed in PyCharm 4.5.4, so if you experience this, try updating your PyCharm.

James Bradbury
  • 1,708
  • 1
  • 19
  • 31
2

I found a solution to this problem that works beautifully on Windows, and wanted to share it.

Solutions that didn't work: I have 16GB of RAM and was still having horrible lag. PyCharm takes less than 1GB of RAM for me, so that wasn't the issue. Turning off inspections didn't help at all, and I didn't have any special plugins that I recall. I also tried playing around with CPU affinities for the process, which briefly worked but not really.

What worked beautifully, almost perfectly:

  1. Set PyCharm's CPU priority to Above Normal
  2. Set the CPU priority for Python processes to Below Normal

You can do this manually, but I recommend using a program which will preserve the setting across restarts and for multiple instances. I used Process Hacker: Right click on the process -> Priority -> Set the priority. Then right click again -> Process -> and select "Save for pycharm64.exe" and similarly for python "Save for python.exe." Finally in Process Hacker go to Options and select "Start when I log on." This will make it so that ALL Pycharm and python executables acquire these CPU priorities, even after restarting the program and/or Windows, and no matter how many python instances you launch.

Basically, much of the PyCharm's lag may be due to conflict with other programs. Think about it: Yes PyCharm requires a lot of CPU, but the PyCharm developers aren't stupid. They have probably at least ensured it can run without lag on an empty core. But now you open Chrome and 30 tabs, Fiddler, an FTP program, iTunes, Word, Slack, etc, and they all compete with PyCharm at the same CPU priority level. Whenever the sum of all programs > 100% on a core, you see lag. Switching to Above Normal priority gives PyCharm something closer to the empty core that it was probably tested on.

As for Below Normal on python.exe, basically you don't want to slow your computer down with your own development. Most python programs are essentially "batch" programs, and you probably won't notice the extra time it takes to run. I don't recommend this if you are developing a graphical interactive program.

Stephen
  • 8,508
  • 12
  • 56
  • 96
  • All of this may be less of an issue with a 4 physical core (8 logical core) computer. In my case I'm stuck with 2 physical cores (4 logical), so it's more important to manage processes doing local development. – Stephen Aug 20 '17 at 01:37
  • 6
    **Warning**: Do not go above Above Normal. If you do this you will compete with Windows processes and possibly cause havoc on your computer. And you would not even make it much faster, if at all. – Stephen Aug 20 '17 at 01:37
0

In my case, it was very slow and i needed to change inspections settings, i tried everything, the only thing that worked was going from 2018.2 version to 2016.2, sometimes is better to be some updates behind...

0

I thought I had a speed issue with PyCharm but in the end it turned out that the output console in PyCharm does not necessarily emulate the output of state-of-the-art terminal applications.

Here's my solution: Click on drop down (arrow) symbol of your configuration -> click edit configuration -> click emulate terminal in output console -> click ok -> Run the configuration.

whiletrue
  • 10,500
  • 6
  • 27
  • 47
0

One setting that may be neglected is the variable loading rule for the python console.

If the workspace contains some convoluted variable objects, the variable loading can really slow things down. and changing the variable loading policy from synchronous to on demand can reduce the reloading and make the execution way faster.

enter image description here

0

Editting Python scripts had a 2-3 second in my case. What helped solved this is discussed here, it suggests (among others) to install the Atom Material Icons plugin for changing folder icons.

It appears icon rendering might have been at fault. I was using the new Pycharms UI which came out in first half of 2023.

Note: Please be careful with plug-ins, although I experienced no issues.

Dudelstein
  • 383
  • 3
  • 16
-1

Everything worked, but I had terrible lag in the code editor until I defined my File - Settings - Project: name - Python Interpreter.

gherson
  • 169
  • 2
  • 9