bug: Slow typing in the Avante window
Describe the bug
Typing in the Avante window is considerably slower than typing in any other buffer.
To reproduce
I could repro the issue with the minimal init.lua.
Even with barely any dependencies, I see that typing in Avante is slow enough to throw me off.
Expected behavior
Avante windows should let me type at the same speed as any other buffer.
Installation method
Use lazy.nvim:
{
"yetone/avante.nvim",
event = "VeryLazy",
build = "make",
version = false,
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons",
},
keys = {
{ "<leader>a", "", desc = "Avante", mode = { "n", "v" } },
},
config = function()
require("avante").setup()
end
},
}
Environment
NVIM v0.10.1 Build type: Release LuaJIT 2.1.1713773202 Run "nvim -V1 -v" for more info
Darwin Varun-MBP.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64
Repro
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro({
spec = {
"yetone/avante.nvim",
event = "VeryLazy",
build = "make",
version = false,
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons",
},
keys = {
{ "<leader>a", "", desc = "Avante", mode = { "n", "v" } },
},
config = function()
require("avante").setup()
end
},
})
I get the same issue. The chat window is very slow. I am quite new to Neovim in general though, so it may be something I have mis-set.
I did some profiling and it's caused by the token counting.
you can disable it through
behaviour = {
enable_token_counting = false,
},
I did some profiling and it's caused by the token counting.
you can disable it through
behaviour = { enable_token_counting = false, },
Same issue here, and this works!
After disable token counting like @sudo-tee suggested.
I still got this issue, typing on all buffer is quite slow if Avante Ask buffer was opened. If its closed, typing is responsive.
NVIM v0.10.3
Build type: Release
LuaJIT 2.1.1736781742
machine = "arm64",
release = "23.6.0",
sysname = "Darwin",
version = "Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:39 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6000"
Installed plugins:
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/nvim-treesitter-textobjects'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.8' }
Plug 'nvim-lualine/lualine.nvim'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-tree/nvim-tree.lua'
Plug 'kylechui/nvim-surround'
Plug 'numToStr/Comment.nvim'
Plug 'folke/todo-comments.nvim'
Plug 'ray-x/go.nvim'
Plug 'ray-x/guihua.lua'
Plug 'rmagatti/auto-session'
Plug 'editorconfig/editorconfig-vim'
Plug 'akinsho/bufferline.nvim', { 'tag': '*' }
Plug 'windwp/nvim-autopairs'
Plug 'jghauser/mkdir.nvim'
Plug 'tpope/vim-repeat'
Plug 'ggandor/leap.nvim'
Plug 'm4xshen/smartcolumn.nvim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
Plug 'jparise/vim-graphql'
" Colorscheme
Plug 'marko-cerovac/material.nvim'
Plug 'tanvirtin/monokai.nvim'
" Cmp related plugin
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" Avante {
" ==============================================================================
" Deps
Plug 'stevearc/dressing.nvim'
Plug 'MunifTanjim/nui.nvim'
Plug 'MeanderingProgrammer/render-markdown.nvim'
" Optional deps
Plug 'echasnovski/mini.pick'
Plug 'HakonHarnes/img-clip.nvim'
Plug 'zbirenbaum/copilot.lua'
Plug 'junegunn/fzf.vim'
Plug 'ibhagwan/fzf-lua'
" Yay, pass source=true if you want to build from source
Plug 'yetone/avante.nvim', { 'branch': 'main', 'do': 'make' }
" } ============================================================================
I'm using vim plug by the way
@novrian
I also got the same problem. It improved a bit after disabling the token counting, but still it slows down all buffers currently open in that nvim until avante window is closed again.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Hi @dtor, thanks for the awesome change! It has greatly improved the usability of this plugin. After this change, I did notice that there is always an initial lag when I first begin typing my prompt. Would it be possible to adjust the debouncing so that there is no lag when I first begin typing?
There is initial token calculation over the entire old prompt (loaded from history) that has to happen. If we just "debounce" it then there will be a pause in the middle of typing, which I consider worse experience. Proper solution would be to calculate it asynchronously, and start showing the count only when calculation is ready. This is much bigger change.
That said, I wonder if I missed some part of the workflow... When exactly do you experience the lag? When you first "
The lag occurs when I first open the avante side panel (even if I haven't typed anything yet). If I wait a second before typing, it comes out smooth.
Right, this is the initial computation that gets you. The costliest operation there is scanning and updating previous chat history, and it is currently pretty inefficient.
You can try "history-handling" branch in my fork of the repo to see how it behaves for you. On my machine history with 417 messages gets processed in 0.12 seconds (compared to 0.32 seconds with code in the main repository). It is not order-of-magnitude difference but still a decent speedup.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.