Skip to content

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:

  1. Irrelevant ranking - Suggestions don’t match usage patterns
  2. Memory bloat - Pylance consumes gigabytes
  3. 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:

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 checking
  • autoImportCompletions: false - Stops suggesting imports from entire codebase
  • indexing: false - Disables full project indexing
  • packageIndexDepths - Limits how deep it analyzes packages
  • userFileIndexingLimit - 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:

settings.json
{
"python.languageServer": "Jedi"
}

You might need to install it first:

Terminal
pip install jedi-language-server

Pros:

  • 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.

Terminal
pip install ty

Then configure VSCode to use it:

settings.json
{
"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:

Conceptual implementation
# Simplified concept
PREFIX_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 + others

Installation:

Terminal
pip install pyhash-complete

You’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 ServerMemory UsageSpeedType AccuracySmart Ranking
Pylance2-4GBMediumBestNo
Jedi200-500MBFastGoodNo
ty~100MBVery FastGoodNo
pyhash-completeVariesFastInherits from baseYes

What I Ended Up With

After testing all options, here’s my current setup:

settings.json
{
"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:

test_server.sh
#!/bin/bash
# Test autocomplete performance with different servers
# Test Jedi
echo "Testing Jedi..."
code --user-data-dir=/tmp/vscode-test --install-extension ms-python.python
# Open Python file, check memory with Activity Monitor
# Test Pylance
echo "Testing Pylance..."
code --user-data-dir=/tmp/vscode-test --install-extension ms-python.vscode-pylance
# Compare memory in Activity Monitor

Or just open Activity Monitor (macOS) or Task Manager (Windows) and watch the memory usage as you switch between language servers.

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