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

perf(buffer previewer): improve performance #584

Merged
merged 89 commits into from
Feb 5, 2024
Merged

Conversation

linrongbin16
Copy link
Owner

@linrongbin16 linrongbin16 commented Feb 4, 2024

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: Query partial fields with `curl` when getting fzf status? junegunn/fzf#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

  • windows
  • macOS
  • linux

Tasks

  • FzfxFiles
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-R to switch between restricted/unrestricted mode, and the lines count is consistent when press multiple times.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file, and open the test/hello world.txt, test/goodbye world/goodbye.lua files.
    • Both fd and find works.
  • FzfxLiveGrep
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-R to switch between restricted/unrestricted mode, and the lines count is consistent when press multiple times.
    • Use -w to match word only, use -g *.lua to search only lua files.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file, and open the test/hello world.txt, test/goodbye world/goodbye.lua files.
    • Both rg and grep works.
  • FzfxBuffers
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-D to delete buffers, and delete the test/hello world.txt, test/goodbye world/goodbye.lua buffers.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file.
  • FzfxGFiles
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-W to switch between workspace/current folder mode.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file.
  • FzfxGLiveGrep
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file.
  • FzfxGStatus
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-W to switch between workspace/current folder mode.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file.
    • Both with/without delta works.
  • FzfxGBranches
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-R/CTRL-O to switch between local/remote branches.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to checkout branch.
  • FzfxGCommits
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-A to switch between git repo commits/current buffer commits.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to copy commit hash.
    • Both with/without delta works.
  • FzfxGBlame
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to copy commit hash.
    • Both with/without delta works.
  • FzfxLspDiagnostics
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-W to switch between workspace/current buffer diagnostics.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file.
  • FzfxLspDefinitions, FzfxLspTypeDefinitions, FzfxLspReferences, FzfxLspImplementations
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Go to definitions/references (this is the most 2 easiest use case when developing this lua plugin with lua_ls).
    • Press ESC to quit, ENTER to open file.
  • FzfxLspIncomingCalls, FzfxLspOutgoingCalls
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Go to incoming/outgoing calls.
    • Press ESC to quit, ENTER to open file.
  • FzfxCommands
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-E/CTRL-A to switch between user/ex/all vim commands.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to feed vim command.
  • FzfxKeyMaps
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-O/CTRL-I/CTRL-A/CTRL-V to switch between normal/insert/visual/all vim key mappings.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to feed vim keys.
  • FzfxFileExplorer
    • Press CTRL-J/CTRL-K to move down/up and preview contents.
    • Press CTRL-U/CTRL-R to switch between filter/include hidden files mode.
    • Press ALT-L/ALT-H to cd into folder and cd upper folder.
    • Use V/W/P/R variants (visual selection, cursor word, yank text, resume last).
    • Press ESC to quit, ENTER to open file, and open the test/hello world.txt, test/goodbye world/goodbye.lua files.
    • All eza/lsd/ls works.

@github-actions github-actions bot added the perf label Feb 4, 2024
Copy link

codecov bot commented Feb 4, 2024

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

❗ 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 ⚠️
lua/fzfx/detail/popup/buffer_popup_window.lua 26.61% 102 Missing ⚠️
lua/fzfx/cfg/_lsp_locations.lua 38.46% 8 Missing ⚠️
lua/fzfx/detail/bat_helpers.lua 68.18% 7 Missing ⚠️
lua/fzfx/cfg/vim_commands.lua 66.66% 6 Missing ⚠️
lua/fzfx/detail/popup.lua 33.33% 6 Missing ⚠️
lua/fzfx/cfg/lsp_diagnostics.lua 44.44% 5 Missing ⚠️
lua/fzfx/cfg/vim_keymaps.lua 64.28% 5 Missing ⚠️
lua/fzfx/cfg/git_branches.lua 57.14% 3 Missing ⚠️
lua/fzfx.lua 0.00% 1 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@linrongbin16 linrongbin16 merged commit b7c580f into main Feb 5, 2024
@linrongbin16 linrongbin16 deleted the perf-buffer-previewer branch February 5, 2024 06:08
This was referenced Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant