voldikss / vim-floaterm

:computer: Terminal manager for (neo)vim
MIT License
2.46k stars 79 forks source link

checktime is very slow #424

Open jackielii opened 7 months ago

jackielii commented 7 months ago

Before reporting

Read

On latest

Yes

Environment

If you are using vim(not neovim), fill in the following blanks

If you are using neovim, just run :checkhealth floaterm and post the content

below.


==============================================================================
floaterm: health#floaterm#check

common ~
- WARNING health#report_start is deprecated, use vim.health.start instead. :help |deprecated|
  This feature will be removed in Nvim version 0.11
- Platform: macos
- WARNING health#report_info is deprecated, use vim.health.info instead. :help |deprecated|
  This feature will be removed in Nvim version 0.11
- Nvim: NVIM v0.10.0-dev-1870+g8fb7419d7-Homebrew
- Plugin: 2383493

terminal ~
- OK Terminal emulator is available
- WARNING health#report_ok is deprecated, use vim.health.ok instead. :help |deprecated|
  This feature will be removed in Nvim version 0.11

floating ~
- OK Floating window is available

Configurations related to vim-floaterm in vimrc(i.e. g:floaterm_xxx):

      vim.g.floaterm_width = 0.8
      vim.g.floaterm_height = 0.9
      vim.g.floaterm_title = "Terminal"
      vim.g.floaterm_titleposition = "left"

Describe your question, feature request, or bug.

I use this to launch Lf (in lazy.nvim config format):

      {
        "<leader>f",
        [[<cmd>FloatermNew --name=Lf --title=Lf lf -command 'map l open' -command 'map o ${{open $f}}' %<cr>]],
        desc = "Lf",
      },

I have this hack for clearing old buffer when I renamed in Lf

      vim.api.nvim_create_autocmd("TermLeave", {
        group = augroup("lf-rename"),
        callback = function()
          for _, buf in ipairs(vim.api.nvim_list_bufs()) do
            local fn = vim.api.nvim_buf_get_name(buf)
            if not vim.bo[buf].readonly and fn ~= "" and vim.fn.filereadable(fn) ~= 1 then
              local success, msg = pcall(vim.api.nvim_buf_delete, buf, { force = true })
              if not success then
                print("Error deleting buffer: " .. msg)
              end
            end
          end
        end,
      })

I create a file call a.txt, open it, and then rename to b.txt. It takes a couple seconds for the new window to appear. I did profile like so:

:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
" :Lf
" rename a.txt to b.txt
" exit Lf
:profile pause
:noautocmd qall!

Open profile you can see:

count  total (s)   self (s)
   11              0.000051   if getbufvar(a:bufnr, '&filetype') != 'floaterm'
    5              0.000005     return
    6              0.000002   endif
    6   0.000067   0.000031   let winid = floaterm#config#get(a:bufnr, 'winid', -1)
    6   0.000056   0.000026   let bd_winid = floaterm#config#get(a:bufnr, 'borderwinid', -1)
    6              0.000025   if has('nvim')
    6   0.000118   0.000043     if s:winexists(winid)
    6   0.002277   0.000255       call nvim_win_close(winid, v:true)
    6              0.000002     endif
    6   0.000055   0.000035     if s:winexists(bd_winid)
    3              0.000296       call nvim_win_close(bd_winid, v:true)
    6              0.000002     endif
                              else
                                if s:winexists(winid)
                                  try
                                    call popup_close(winid)
                                  catch
                                    if bufwinnr(a:bufnr) > 0
                                      silent! execute bufwinnr(a:bufnr) . 'hide'
                                    endif
                                  endtry
                                endif
    6              0.000002   endif
    6   2.018704   2.014513   silent checktime

FUNCTIONS SORTED ON TOTAL TIME
count  total (s)   self (s)  function
    3   2.070671   0.000563  <SNR>86_on_floaterm_close()
   11   2.026199   2.017709  floaterm#window#hide()
    3   0.083617   0.000427  floaterm#run()
    3   0.080499   0.007887  floaterm#new()
    3   0.069290   0.000453  floaterm#terminal#open()
    3   0.068389   0.015052  <SNR>86_spawn_terminal()
    3   0.042820   0.002289  <SNR>85_lf_callback()
    2   0.040509   0.011804  floaterm#util#open()
    3   0.024242   0.000441  <SNR>86_on_floaterm_create()
    3   0.018436   0.000173  floaterm#window#open()
    3   0.017782   0.004098  <SNR>89_open_float()
    5   0.015929   0.015465  <SNR>1_LoadFTPlugin()
    8   0.012547   0.000811  <SNR>13_Init()
    5   0.012499   0.000050  <SNR>13_AutoInit()
    5   0.010880             <SNR>36_SynSet()
   79   0.009437   0.002457  coc#rpc#notify()
   66   0.008702   0.000930  <SNR>51_Autocmd()
    5   0.007178   0.001322  <SNR>13_DetectDeclared()
   79   0.006301   0.005852  <SNR>54_notify()
    5   0.003786   0.001966  <SNR>13_DetectHeuristics()

FUNCTIONS SORTED ON SELF TIME
count  total (s)   self (s)  function
   11   2.026199   2.017709  floaterm#window#hide()
    5   0.015929   0.015465  <SNR>1_LoadFTPlugin()
    3   0.068389   0.015052  <SNR>86_spawn_terminal()
    2   0.040509   0.011804  floaterm#util#open()
    5              0.010880  <SNR>36_SynSet()
    3   0.080499   0.007887  floaterm#new()
   79   0.006301   0.005852  <SNR>54_notify()
    3   0.017782   0.004098  <SNR>89_open_float()
    5              0.003766  <SNR>2_LoadIndent()
    5   0.003196   0.002722  coc#util#editor_infos()
   79   0.009437   0.002457  coc#rpc#notify()
    5              0.002323  <SNR>13_DetectEditorConfig()
    3   0.042820   0.002289  <SNR>85_lf_callback()
    5   0.003786   0.001966  <SNR>13_DetectHeuristics()
   15   0.002087   0.001865  <SNR>21_Highlight_Matching_Pair()
    3   0.002691   0.001775  floaterm#cmdline#parse()
    4              0.001706  <SNR>13_Guess()
    3   0.002195   0.001629  floaterm#buffer#create_scratch_buf()
   15              0.001538  <SNR>13_Capture()
   10              0.001489  coc#float#get_float_win_list()

I think checktime shouldn't be called here. It should be an option to enable at best or users should configure base on their own cases.

jackielii commented 7 months ago

would be great to have a user command that fires on Floaterm exit?