How Can I Improve Python Autocomplete in VSCode?
I typed os. in VSCode and got os.abort as the first suggestion. I almost never use that function. Where’s os.path? Where’s os.remove? The things I actually need?
This drove me crazy. Let me show you how I fixed it.
The Problem: Irrelevant Suggestions and Memory Bloat
When I opened VSCode and typed os., the autocomplete showed me options I rarely used - os.abort, os.CLD_CONTINUED - instead of the functions I actually use like os.path or os.remove.
The ranking seemed completely random. Alphabetical? By signature? Either way, it wasn’t helpful.
Then I checked my Activity Monitor. Pylance was using 4GB of RAM. For autocomplete. That’s insane.
Three issues I needed to solve:
- Irrelevant ranking - Suggestions don’t match usage patterns
- Memory bloat - Pylance consumes gigabytes
- Slow performance - Heavy memory leads to sluggish response
Solution 1: Optimize Pylance Settings (Quick Fix)
Pylance is the default language server in VSCode. It’s powerful but resource-hungry. I tried tuning it first.
Open your settings.json:
{ "python.analysis.typeCheckingMode": "off", "python.analysis.autoImportCompletions": false, "python.analysis.indexing": false, "python.analysis.packageIndexDepths": [ { "name": "", "depth": 2 } ], "python.analysis.userFileIndexingLimit": 2000}What these do:
typeCheckingMode: "off"- Disables expensive type checkingautoImportCompletions: false- Stops suggesting imports from entire codebaseindexing: false- Disables full project indexingpackageIndexDepths- Limits how deep it analyzes packagesuserFileIndexingLimit- Caps the number of user files indexed
Result: Memory dropped from 4GB to 1.5GB. Still not great, but better. Autocomplete became faster but suggestions were still irrelevant.
Solution 2: Switch to Jedi Language Server
Jedi is a mature, lightweight alternative that’s been around for years. It’s not as feature-rich as Pylance but uses far less memory.
In your settings.json:
{ "python.languageServer": "Jedi"}You might need to install it first:
pip install jedi-language-serverPros:
- Memory usage dropped to ~300MB
- Faster response time
- Stable and battle-tested
Cons:
- Less accurate type hints
- Fewer advanced features
- Suggestions still ranked poorly
I liked the memory savings, but the ranking problem persisted.
Solution 3: Try ty Type Checker
ty is a newer, minimal type checker designed for performance. It’s lighter than Pylance but still under active development.
pip install tyThen configure VSCode to use it:
{ "python.languageServer": "Pylance", "python.analysis.typeCheckingMode": "basic", "python.analysis.extraPaths": ["${workspaceFolder}"]}Wait, ty doesn’t have a VSCode extension yet. You’d need to use it as a standalone type checker or through Neovim. So this wasn’t a real option for me in VSCode.
Solution 4: pyhash-complete - The Community Solution
Then I found pyhash-complete. A developer named matan-h had the same problem and built a solution.
The idea: Create a hash table of commonly-used prefixes, then reorder autocomplete suggestions based on real-world usage.
Here’s how it works internally:
# Simplified conceptPREFIX_HASH = { "os.": ["path", "remove", "listdir", "makedirs", "getcwd"], "str.": ["split", "join", "replace", "strip", "encode"], "list.": ["append", "extend", "pop", "sort", "reverse"]}
def rank_suggestions(prefix, suggestions): common = PREFIX_HASH.get(prefix, []) # Move common items to front ranked = [s for s in suggestions if s in common] others = [s for s in suggestions if s not in common] return ranked + othersInstallation:
pip install pyhash-completeYou’ll need to configure your editor to use it. Check the GitHub repo for the latest setup instructions.
Pros:
- Smart, usage-based ranking
- Learns from actual usage patterns
- Open source and extensible
Cons:
- Requires manual setup
- Not as integrated as native Pylance
- Still in early development
Comparison Table
| Language Server | Memory Usage | Speed | Type Accuracy | Smart Ranking |
|---|---|---|---|---|
| Pylance | 2-4GB | Medium | Best | No |
| Jedi | 200-500MB | Fast | Good | No |
| ty | ~100MB | Very Fast | Good | No |
| pyhash-complete | Varies | Fast | Inherits from base | Yes |
What I Ended Up With
After testing all options, here’s my current setup:
{ "python.languageServer": "Jedi", "python.jediMemory": true, "python.analysis.typeCheckingMode": "off", "python.analysis.autoImportCompletions": false}I use Jedi for the low memory footprint and accept the tradeoff of less accurate type hints. When I need better type checking, I toggle Pylance back on temporarily.
For the ranking issue, I’m watching pyhash-complete. It’s promising but not quite ready for my daily workflow.
Why This Matters
Every time I scroll past os.abort to find os.path, I lose a second. Multiply that by hundreds of autocomplete interactions per day, and I’m wasting minutes. A modern IDE should learn from my usage patterns.
More importantly, the 4GB memory bloat affects my entire system. My browser slows down. My Docker containers suffer. That’s unacceptable for a typing assistance tool.
Practical Workflow: Test Different Servers
If you want to experiment, here’s a quick testing method:
#!/bin/bash# Test autocomplete performance with different servers
# Test Jediecho "Testing Jedi..."code --user-data-dir=/tmp/vscode-test --install-extension ms-python.python# Open Python file, check memory with Activity Monitor
# Test Pylanceecho "Testing Pylance..."code --user-data-dir=/tmp/vscode-test --install-extension ms-python.vscode-pylance
# Compare memory in Activity MonitorOr just open Activity Monitor (macOS) or Task Manager (Windows) and watch the memory usage as you switch between language servers.
Related Knowledge
Language Server Protocol (LSP): VSCode uses LSP to communicate with language servers. Pylance, Jedi, and others implement this protocol. You can mix and match.
Why Pylance uses so much memory: It pre-computes type information for your entire virtual environment and project. Great for accuracy, terrible for RAM.
Future of Python tooling: The community is pushing for faster, lighter tools. Projects like ruff for linting and ty for type checking show that we don’t need to accept slow, heavy tools.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments