Skip to content

Defer Treesitter setup to improve startup time of nvim {filename}#448

Merged
feoh merged 1 commit intonvim-lua:masterfrom
AshrafMichail23:main
Oct 2, 2023
Merged

Defer Treesitter setup to improve startup time of nvim {filename}#448
feoh merged 1 commit intonvim-lua:masterfrom
AshrafMichail23:main

Conversation

@AshrafMichail23
Copy link

@AshrafMichail23 AshrafMichail23 commented Sep 30, 2023

Wrapping the require('nvim-treesitter.configs').setup block in a vim.defer_fn(function()...end, 0) saves 185ms of startup time when loading a file with an expensive Treesitter parser such as: nvim test.cc.

Default init.lua:
302.407 000.007: --- NVIM STARTED ---

Adding vim.defer_fn around require('nvim-treesitter.configs').setup block:
115.798 000.005: --- NVIM STARTED ---

The 185ms startup delay does not occur when loading a simple .txt file or .lua file.

Changes visual experience:
Before: slower startup + treesitter colors available first frame
After: faster startup + treesitter colors come in after first frame

Closes #435

@feoh
Copy link
Collaborator

feoh commented Sep 30, 2023

@AshrafMichail23 This PR is still marked as a WIP, are you still actually working on it?

@AshrafMichail23 AshrafMichail23 marked this pull request as ready for review October 1, 2023 03:55
@AshrafMichail23
Copy link
Author

@AshrafMichail23 This PR is still marked as a WIP, are you still actually working on it?

Marked as "ready for review".

@feoh
Copy link
Collaborator

feoh commented Oct 2, 2023

OK I just tested this myself. I don't see any downsides here! Merging.

Folks please yell if this impacts you in any way, and @AshrafMichail23 thanks for your contribution!

@feoh feoh merged commit f15af9b into nvim-lua:master Oct 2, 2023
qiuye2015 pushed a commit to qiuye2015/fjp.nvim that referenced this pull request Dec 10, 2023
Defer Treesitter setup to improve startup time of nvim {filename}
cbmorrell pushed a commit to cbmorrell/kickstart-modular.nvim that referenced this pull request Apr 22, 2024
Defer Treesitter setup to improve startup time of nvim {filename}
s-frick pushed a commit to s-frick/kickstart.nvim that referenced this pull request Jul 29, 2024
Defer Treesitter setup to improve startup time of nvim {filename}
melobern added a commit to melobern/kickstart.nvim that referenced this pull request Oct 30, 2024
Defer Treesitter setup to improve startup time of nvim {filename}
felixhummel added a commit to felixhummel/nvim that referenced this pull request Dec 19, 2024
Defer Treesitter setup to improve startup time of nvim {filename}
restray added a commit to restray/kickstart.nvim that referenced this pull request Mar 16, 2025
Defer Treesitter setup to improve startup time of nvim {filename}
tkappedev pushed a commit to tkappedev/kickstart.nvim that referenced this pull request Jun 14, 2025
Defer Treesitter setup to improve startup time of nvim {filename}
apriljarosz pushed a commit to apriljarosz/kickstart.nvim that referenced this pull request Jun 19, 2025
Defer Treesitter setup to improve startup time of nvim {filename}
eduardofuncao pushed a commit to eduardofuncao/config.nvim that referenced this pull request Aug 5, 2025
Defer Treesitter setup to improve startup time of nvim {filename}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require('nvim-treesitter.configs').setup adds 185ms to startup time when loading C++ file

3 participants