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: fix redundant docs rendering #113

Closed
wants to merge 1 commit into from

Conversation

eero-lehtinen
Copy link
Contributor

@eero-lehtinen eero-lehtinen commented Oct 14, 2024

After 05229dd adding the use of stylize_markdown, I consistently experience half second stutters when docs are open and switching between items. Nvim-cmp has zero issues with this.

Basically I copied what nvim-cmp does, which removed all performance issues for me. The buffer is cleared more efficiently. nvim_buf_set_lines is not used redundantly only to be instantly overridden by stylize_markdown. Setting the "modified" option is moved to the end of the function.

@eero-lehtinen eero-lehtinen force-pushed the improve-docs-perf branch 2 times, most recently from f510705 to e02c1ef Compare October 14, 2024 22:47
@Saghen Saghen self-requested a review October 15, 2024 01:40
@scottmckendry
Copy link
Collaborator

scottmckendry commented Oct 15, 2024

I've A-B tested doc performance with both this PR and main and there definitely an improvement here, however slight.

I did notice the doc output looks different. For example, this is main:
image

And with your changes:
image

The latter looks better, IMO. Any idea why this is?

Edit: just realised this is the exact problem that this PR is addressing 🤦 LGTM!

@eero-lehtinen
Copy link
Contributor Author

eero-lehtinen commented Oct 15, 2024

I'm not sure why main looks different to you. For me this PR looks the same.

The lag seems to be much more pronounced with rust-analyzer for some reason. With lua_ls it didn't really make a difference. I also tested on another machine with the same config and there was less lag than on my main machine, so maybe it's more complicated.

The lag is also much worse on nvim nightly.

main with nvim nightly (After the first 6 secs I start tapping quickly and it stutters badly):

Screencast_20241015_123926.webm

this PR with nvim nightly (I'm tapping just as quick and there is no stutter):

Screencast_20241015_124018.webm

It doesn't show that well on video because KDE Spectacle seems to add its own lag but it feels way better.

@Saghen Saghen closed this in 90d6394 Oct 15, 2024
@Saghen
Copy link
Owner

Saghen commented Oct 15, 2024

Thanks for finding this regression! I wasn't happy with the performance even if we cached it and noticed that it was using regex highlighting instead of treesitter. I took inspiration from the vim.treesitter.highlighter code to highlight the documentation window ourselves. It has a high initial cost of 50ms for compiling the markdown query, but afterwards, it updates in 1-8ms. Lmk if performance looks good on your end

@eero-lehtinen
Copy link
Contributor Author

Performance feels great now. Also looks better with treesitter. Thanks!

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.

3 participants