Asynchronous Operations
nvim-treesitter performs installation operations asynchronously by default, allowing Neovim to remain responsive during long-running tasks.How Async Works
The async implementation (lua/nvim-treesitter/async.lua) provides:- Non-blocking I/O for network downloads and file operations
- Parallel task execution for installing multiple parsers
- Graceful cancellation when operations are interrupted
- Error handling with detailed stack traces
Async vs Synchronous Installation
Asynchronous (default):Handling Async Tasks
Wait with timeout:Parallel Installation
By default, nvim-treesitter installs up to 100 parsers in parallel (lua/nvim-treesitter/install.lua:60). This significantly speeds up bulk installations.How Parallel Installation Works
Thejoin() function (lua/nvim-treesitter/install.lua:66-91) manages parallel task execution:
- Up to
max_jobstasks run simultaneously - As each task completes, a new one starts from the queue
- All tasks must complete before the operation finishes
Controlling Parallelism
Use themax_jobs option to limit concurrent installations:
Limited Memory Systems
Limited Memory Systems
Each parser compilation can use 200-500MB of RAM. On systems with limited memory:This trades speed for memory efficiency.
Low Bandwidth Connections
Low Bandwidth Connections
Parallel downloads may saturate bandwidth and cause timeouts:
Shared Build Servers
Shared Build Servers
Grammar Generation
Grammar Generation
When using
generate = true, each task runs tree-sitter generate which is CPU and memory intensive:Update Operations
Themax_jobs option also applies to updates:
Installation Timeouts
Each parser installation has a 60-second timeout (lua/nvim-treesitter/install.lua:61). If another installation of the same language is already running, the installer waits for it to complete.Handling Timeouts
If installations frequently timeout:-
Check network connectivity:
-
Increase wait timeout for manual installations:
-
Install problematic parsers individually:
Memory Optimization
Installation Memory Usage
Each parser installation involves:- Download: Minimal memory (streaming)
- Extraction: ~50-100MB temporary disk space
- Compilation: 200-500MB RAM per parser
- Installation: Minimal (file copy)
Reducing Memory Footprint
Sequential installation (lowest memory):Cleanup Temporary Files
Temporary files are automatically cleaned up after installation (lua/nvim-treesitter/install.lua:434-438):- Downloaded tarballs are deleted after extraction
- Extracted source directories are removed after compilation
- Only the compiled
.soparser and query symlinks remain
Network Performance
Download Optimization
Parsers are downloaded from GitHub as tarballs (lua/nvim-treesitter/install.lua:199-227):- Uses
curlwith retry logic (7 attempts) - Follows redirects automatically (
-L) - Shows minimal output (
--silent --show-error) - Caches downloads in
stdpath('cache')
Proxy Configuration
If you’re behind a proxy, configure curl:Offline Installation
For air-gapped systems, you can use local parser repositories:- Use the local directory instead of downloading
- Compile from the local source
- Link queries from the local repository if available
Compilation Performance
Tree-sitter Build
Parsers are compiled usingtree-sitter build (lua/nvim-treesitter/install.lua:279-291):
- Compiles the parser with optimizations
- Links against the tree-sitter runtime
- Produces a shared library (
.so,.dll, or.dylib)
Grammar Generation
When usinggenerate = true, the grammar is regenerated before compilation:
Query Performance
Query Installation
Queries are installed by symlinking (Unix) or copying (Windows) from the runtime directory (lua/nvim-treesitter/install.lua:411-432). Symlink (preferred):- Fast (instant)
- No disk space duplication
- Automatically reflects updates to bundled queries
- Slower for large query collections
- Duplicates disk space
- Requires manual updates
Query Cache
Neovim caches parsed queries in memory. Clear the cache if queries are modified:Monitoring Performance
Installation Progress
Enable logging to monitor installation performance:- Download times
- Compilation duration
- File operations
- Error messages
Profiling
Profile installation time:Best Practices
Startup Performance
Parser loading has minimal impact on Neovim startup:- Parsers are loaded on-demand per filetype
- Compiled parsers are memory-mapped (not copied)
- Queries are parsed once and cached
See Also
- Configuration - Custom installation directory setup
- Troubleshooting - Common performance issues
- API Reference - Installation options reference