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

feat: save unused buffers in buffer pool #536

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

apollo1321
Copy link
Contributor

Closes #533

local buf = api.nvim_create_buf(false, true)

vim.bo[buf].undolevels = -1
vim.bo[buf].bufhidden = 'wipe'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option deletes the buffer after the window is closed. It appears that the problem existed before multi-window support was introduced.

lua/treesitter-context/render.lua Outdated Show resolved Hide resolved
lua/treesitter-context/render.lua Outdated Show resolved Hide resolved
lua/treesitter-context/render.lua Outdated Show resolved Hide resolved
end
api.nvim_win_close(context_winid, true)
if bufnr ~= nil and api.nvim_buf_is_valid(bufnr) then
table.insert(buffer_pool, bufnr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the only entry point to actually inserting a buffer into the pool is here, so can't we avoid need for the delete_excess_buffers() call by simply not inserting a buffer if the pool is at capacity?

Copy link
Contributor Author

@apollo1321 apollo1321 Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't delete buffers in-place, when the command-line window is open, see #507

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not what is being suggested?

Copy link
Contributor Author

@apollo1321 apollo1321 Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, no. If the pool is at capacity and we don't add a buffer, we'll need to delete one. However, if the command-line window is open, we cannot proceed with the deletion. Regardless, sometimes we have to add the buffer to the pool even if the pool is full. While I could introduce another 'if' branch to handle the case when the pool if full and we are not in command-line mode, I doubt it would enhance performance.

Copy link
Contributor Author

@apollo1321 apollo1321 Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I'm not certain it's a good idea to check all buffers in the pool within the delete_excess_buffers function. We might just delete the last buffers in the list instead. I don't believe the buffers will become invalid without a reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah tricky, well the improved implementation should do though!

@lewis6991 lewis6991 merged commit b9e3033 into nvim-treesitter:master Dec 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can the context scratch buffers be reused?
3 participants