Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay actual highlight to make buffer open instantly #6270

Closed
xzbdmw opened this issue Mar 9, 2024 · 2 comments
Closed

Delay actual highlight to make buffer open instantly #6270

xzbdmw opened this issue Mar 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@xzbdmw
Copy link

xzbdmw commented Mar 9, 2024

Is your feature request related to a problem? Please describe.
When enable ts highlight in rust files, things such as go to definition or telescope find_files always need 0.02~0.05s to load, which is a noticeable delay.
I measured this using

local start_time = nil
local end_time = nil
vim.api.nvim_create_autocmd("BufLeave", {
    callback = function()
        start_time = os.clock()
    end,
})
vim.api.nvim_create_autocmd("BufEnter", {
    callback = function()
        end_time = os.clock()
        if start_time then
            local elapsed_time = end_time - start_time
            print("Buffer switch time: " .. elapsed_time .. " s")
        end
        
    end,
})

Turn off ts highlight makes navigation much smoother. Although the lag only happened at fitst load time.
Describe the solution you'd like
Add an option to Delay actual highlight(parse) time to make buffer open instantly.

Describe alternatives you've considered
Maybe cache the result per session or pre-parse workspace files?

Additional context
I tried helix and their ts parse is crazy fast, open buffer first time(go to definition to std) have no feeling of any delay, I wander Why neovim doing this slow.

@xzbdmw xzbdmw added the enhancement New feature or request label Mar 9, 2024
@xzbdmw
Copy link
Author

xzbdmw commented Mar 10, 2024

More infomation, nvim-0.10 is much slower than nvim-0.95 for opening buffer,take this init.lua for example

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable", -- latest stable release
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
	{
		"mrcjkb/rustaceanvim",
		-- version = "^3", -- Recommended
		ft = { "rust" },
	},
})
vim.keymap.set("n", "gd", function()
	vim.lsp.buf.definition()
end)
local start_time = nil
local end_time = nil
vim.api.nvim_create_autocmd("BufLeave", {
    callback = function()
        start_time = os.clock()
    end,
})
vim.api.nvim_create_autocmd("BufEnter", {
    callback = function()
        end_time = os.clock()
        if start_time then
            local elapsed_time = end_time - start_time
            print("Buffer switch time: " .. elapsed_time .. " s")
        end
        
    end,
})

open an simple rust file and put cursor at such as Vec::new, type gd, in 0.10 it takes 0.015s and 0.008s in 0.95 in my mac(without treesiter).
with treesitter enabled, the time is 0.037(0.10) vs 0.020(0.9.5).

@clason
Copy link
Contributor

clason commented Mar 10, 2024

Highlighting is performed by Neovim, not this plugin, so this is not actionable here. And these steps are much too complex and involve LSP, so are not good regression benchmarks anyway.

@clason clason closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants