Narrow the scope of code completion suggestions for performance

One of the worst pain points of PyCharm these days is the slowness of code completion when working in large projects. My company uses a monorepo structure which causes PyCharm to index the entire thing and use it for code completion. I would like to be able to narrow the scope of where it searches for symbols to suggest. 99% of the time, I'm typing the name of a symbol that is defined somewhere in the file that I'm editing, yet PyCharm is suggesting things like the names of PyTest functions that are located in entirely different areas of the repository. I've already tried every variation of settings relating to code completion but it looks like it's just a built-in methodology. If we're able to narrow our find-in-path and find usages searches to just the open files, we should be able to do the same with our code completion suggestions.

3
4 comments

Hi, you can exclude specific directories from indexing by marking them as "Excluded" in the project structure settings (https://www.jetbrains.com/help/pycharm/project-structure-dialog.html)

You can also mark a directory as excluded from the context menu in project view.

0

That's not a satisfactory solution since, unless I'm wrong, excluding module directories in our codebase would break many other features including the resolution of imports. This is a difficult situation as I imagine the resolution of imports uses the same functionality. Yet, if when writing an import statement, PyCharm already knows to suggest only the names of indexed modules, it doesn't seem like much of a stretch to add the functionality to restrict suggestions when writing code in the method or class scope.

0

Maybe it would help to disable "Show completion as you type" in "Preferences | Editor | General | Code Completion"? It would require and explicit shortcut to call the completion list, meaning it shouldn't appear when you don't need it, increasing the overall performance.

0

That defeats the purpose of having typeahead code completion. Stopping typing to hit a shortcut, then waiting for it to spend valuable compute time looking through irrelevant indexed modules only to find that I haven't typed enough characters to narrow down the list enough makes the problem twice as bad.

0

Please sign in to leave a comment.