avante.nvim icon indicating copy to clipboard operation
avante.nvim copied to clipboard

bug: Slow typing in the Avante window

Open V4G4X opened this issue 1 year ago • 4 comments

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
    },
})

V4G4X avatar Oct 12 '24 06:10 V4G4X

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.

Apoc182 avatar Jan 13 '25 04:01 Apoc182

I did some profiling and it's caused by the token counting.

you can disable it through

    behaviour = {
      enable_token_counting = false,
    },

sudo-tee avatar Feb 04 '25 17:02 sudo-tee

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!

LiYaoYu avatar Apr 24 '25 14:04 LiYaoYu

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 avatar Apr 30 '25 07:04 novrian

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

felixpohlmann avatar Jun 03 '25 15:06 felixpohlmann

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.

github-actions[bot] avatar Jul 04 '25 02:07 github-actions[bot]

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?

carbon-steel avatar Jul 07 '25 09:07 carbon-steel

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 "at" and immediately start typing? Some other scenario?

dtor avatar Jul 07 '25 16:07 dtor

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.

carbon-steel avatar Jul 09 '25 13:07 carbon-steel

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.

dtor avatar Jul 11 '25 05:07 dtor

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.

github-actions[bot] avatar Aug 30 '25 02:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 04 '25 02:09 github-actions[bot]