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

Semantic highlighting optimisation #4150

Merged

Conversation

puremourning
Copy link
Member

@puremourning puremourning commented Jun 10, 2023

Minimise overdraw and over-request for semantic tokens.
Share the scrolling window implementation with inlay hints which was already a bit better.


This change is Reviewable

@puremourning puremourning force-pushed the semantic-highlighting-optimisation branch 2 times, most recently from addf4f5 to 6ecb7b4 Compare June 10, 2023 16:10
@codecov
Copy link

codecov bot commented Jun 10, 2023

Codecov Report

Merging #4150 (187489d) into master (0d387ad) will increase coverage by 2.69%.
The diff coverage is 78.70%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4150      +/-   ##
==========================================
+ Coverage   86.14%   88.84%   +2.69%     
==========================================
  Files          33       34       +1     
  Lines        4389     4393       +4     
==========================================
+ Hits         3781     3903     +122     
+ Misses        608      490     -118     

Re-use the "optimal range" drawing used by inlay hints, i.e. only
re-request if the new visible range is not covered by the previously
requested visible range.

Essentially, semantic highlighting and inlay hints now use the (almost)
exact same code.

Still TODO (for both): record the _actual_ received range and compare
against that. The point is that we should only redraw if the new range
isn't within the last _drawn_ range. This is important for semantic
highlighting because servers might not support range highlighting and we
should therefore paint the whole buffer and only re-do that when it
changes.
This means that if the servers return a wider range of semantic tokens
or inlay hints than we requested, we don't constantly re-request them
whenever the viewport moves.

Importantly, clangd doesn't support range tokens, so we previously
requested and re-parsed, deleted and re-added every single token on
every single scroll event. This meant that scrolling was very slow and
lots of wasted effort. This should help reduce that. We should
essentially re-use the tokens on scolling and pretty much never
re-request them unless the buffer changes or we have a
file-ready-to-parse.
@puremourning puremourning force-pushed the semantic-highlighting-optimisation branch from 6ecb7b4 to 724218e Compare June 10, 2023 16:25
Copy link
Member Author

@puremourning puremourning left a comment

Choose a reason for hiding this comment

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

:lgtm:

need to test this for a bit in practice but them merge

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: 1 of 2 LGTMs obtained (waiting on @puremourning)

@puremourning
Copy link
Member Author

Scrolling behaviour much improved.

however, there are still forceful requests happening that aren't really needed, such as when doing G or gg. Possibly off-by-one-like behaviour in the range comparison.

Really should finally write some tests for these features.

Clangd now includes all stdlib stuff by default in the initial search,
so we sometimes match random stdlib symbols. Make the symbols we search
for a little more unique by prefixing with x
Copy link
Member Author

@puremourning puremourning left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r2, all commit messages.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale) (waiting on @puremourning)

Copy link
Member Author

@puremourning puremourning left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 1 of 2 LGTMs obtained (waiting on @puremourning)

Copy link
Member Author

@puremourning puremourning left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 1 of 2 LGTMs obtained (waiting on @puremourning)

@puremourning puremourning added the Ship It! Manual override to merge a PR by maintainer label Jun 12, 2023
@puremourning puremourning merged commit 49ced5a into ycm-core:master Jun 12, 2023
9 of 10 checks passed
@puremourning puremourning deleted the semantic-highlighting-optimisation branch June 12, 2023 20:05
@mergify
Copy link
Contributor

mergify bot commented Jun 12, 2023

Thanks for sending a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ship It! Manual override to merge a PR by maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant