linrongbin16 / fzfx.nvim

A Neovim fuzzy finder that updates on every keystroke.
https://linrongbin16.github.io/fzfx.nvim/
MIT License
122 stars 5 forks source link

perf(buffer previewer): improve performance #584

Closed linrongbin16 closed 7 months ago

linrongbin16 commented 7 months ago

I changed the internal implementation of communication between provider and buffer previewer.

In previous implementation, I'm using --bind=focus:execute-silent(echo {} > cache_file) to dump fzf's current pointer's line into a cache_file, and watch the file's change with uv.new_fs_event. then render the line (actually a file name) to the buffer previewer.

The uv's fs event is awesome, but binding echo to fzf could lead to stucking, since fzf's focus event is running in sync mode, not async. so when you typing fast, it could be quite laggy. I hate it.

In this PR, I use the fzf's experimental feature: curl localhost:port to get the fzf current status. It will output a json string with: {"current":{"index":97,"text": "lua/fzfx.lua"}}, the current.text is exactly the current fzf's pointer's line.

So I'm trying to get the current line data with uv.spawn, which is also async, it should have better performance. But actually I still met some performance bottle necks:

  1. the json output of fzf status is super big, because it contains all the lines in the left side of fzf. I submit a question about this: https://github.com/junegunn/fzf/discussions/3611, hope I could partially query only the current field. For now I'm using a partial decoding method, to hack into the json and retrieve only the current field.
  2. Render all the lines of a file could eat a lot of CPU. I rewrite the buffer previewer, and only render the lines in the previewer window. Thus the rendering should be lazy, e.g. only render the lines that user need to see.

Regresion test

Platforms

Tasks

codecov[bot] commented 7 months ago

Codecov Report

Attention: 260 lines in your changes are missing coverage. Please review.

Comparison is base (194d338) 75.17% compared to head (7cf30b5) 77.74%.

:exclamation: Current head 7cf30b5 differs from pull request most recent head e838972. Consider uploading reports for the commit e838972 to get more accurate results

Files Patch % Lines
lua/fzfx/detail/general.lua 30.37% 110 Missing :warning:
lua/fzfx/detail/popup/buffer_popup_window.lua 26.61% 102 Missing :warning:
lua/fzfx/cfg/_lsp_locations.lua 38.46% 8 Missing :warning:
lua/fzfx/detail/bat_helpers.lua 68.18% 7 Missing :warning:
lua/fzfx/cfg/vim_commands.lua 66.66% 6 Missing :warning:
lua/fzfx/detail/popup.lua 33.33% 6 Missing :warning:
lua/fzfx/cfg/lsp_diagnostics.lua 44.44% 5 Missing :warning:
lua/fzfx/cfg/vim_keymaps.lua 64.28% 5 Missing :warning:
lua/fzfx/cfg/git_branches.lua 57.14% 3 Missing :warning:
lua/fzfx.lua 0.00% 1 Missing :warning:
... and 7 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #584 +/- ## ========================================== + Coverage 75.17% 77.74% +2.57% ========================================== Files 51 51 Lines 6114 5757 -357 ========================================== - Hits 4596 4476 -120 + Misses 1518 1281 -237 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.