sphamba / smear-cursor.nvim

🚄 Neovim plugin to animate the cursor with a smear effect in all terminals
GNU General Public License v3.0
281 stars 6 forks source link

Buffers & Windows keep increasing #5

Closed folke closed 3 days ago

folke commented 4 days ago

The total number of open buffers/windows keeps increasing. Neovim became really slow at some point, and it seemed there were over a 1000 buffers and windows open, created by smear.

Apart from that, I really like how it looks :)

My options:

{
    legacy_computing_symbols_support = true,
    hide_target_hack = false,
  }
sphamba commented 4 days ago

Thank you for raising this issue!

Indeed, I made the choice to keep floating windows open, because creating them the first time can be slow due to interaction with syntax highlighting plugins (namely vim-airline, with BufWinEnter and BufUnload events). That said, I'll work on a garbage collection mechanism that get rids of inactive floating windows :)

folke commented 4 days ago

You should probably also set the noautocmd option when creating a window, so that other plugins won't trigger autocmds.

folke commented 4 days ago

Maybe just create a fixed number of windows and then re-use those? (as long as they're valid)

sphamba commented 3 days ago

Windows are already reused (that's why I don't close them). And there must be enough of them to draw every cell that cannot be an extmark, because I naively use one window per cell 🥴. Also, there is one set of window per tab, which could explain how you have so many. Deleting the unused windows (eg those on invisible tabs) would be my way to go

sphamba commented 3 days ago

My options:

{
    legacy_computing_symbols_support = true,
    hide_target_hack = false,
  }

I am curious about which font you use that supports legacy computing symbols. 😃

folke commented 3 days ago

ok, that explains it. In my case that would eventually get to 15104 windows. (lines * columns) I don't use tabs, so that's fine. In terms of re-use I was thinking of just keeping enough windows needed to render a trail. Like 20 or so? And then just reposition them. So keep track if a window is used right now and if not re-use it to render a cell and re-position it?

folke commented 3 days ago

Something else that could work, is to have just one transparent window covering the whole screen on a buf with empty lines equal to vim.o.lines. You could then use nvim_set_extmark with fixed win_col offsets.

but you may have already tried that :)

sphamba commented 3 days ago

Ouch! That might actually be a bug... There should indeed (in principle) be as many windows as cells needed to render one trail (around 2-3 times the trail's length). And they get repositionned and hidden on demand. Also, they should only be used over wrapped lines and between panes (where extmarks don't work). So there is something wrong going on. Could I see your config?

And yes, I tried the single fully transparent window, but it does not work without the legacy computing symbols set, because I need to invert the color of available symbols, and the color blending computation does crazy things.

folke commented 3 days ago

To trigger the issue, just open a split with two buffers and then keep switching between both buffers. Not need to move inside the buffer. Just keep switching to and back. #vim.api.nvim_list_wins() keeps increasing in my case.

folke commented 3 days ago

idle CPU also keeps increasing and gets close to 100% after a while

sphamba commented 3 days ago

To trigger the issue, just open a split with two buffers and then keep switching between both buffers. Not need to move inside the buffer. Just keep switching to and back. #vim.api.nvim_list_wins() keeps increasing in my case.

I cannot reproduce with my current config on commit 8505320. My window count stagnates below 40.

folke commented 3 days ago

Still need to figure out how to reproduce it correctly. windows remain around 50 for me, and then all of the sudden there's an extra 50. Then after a while, another 50.

Will debug and see if I can find something.

sphamba commented 3 days ago

Could it be that the smear-cursor plugin gets periodically silently reloaded? That would result in reinitializing the variables that contains the list of references to opened windows (thus forgetting that windows already exist). The (local) variables in question are in lua/smear_cursor/draw.lua, window_ids and n_active_windows.

sphamba commented 3 days ago

Well, I made the lists of windows global, just in case. You can try commit 9b10c94

folke commented 3 days ago

Could it be that the smear-cursor plugin gets periodically silently reloaded?

Nope, nothing in my config does that.

I think I can no longer trigger the issue right now. Might've been on an older commit.

I'm still on the commit before 9b10c94.

Will close this issue for now and see if it happens again.

Thanks!