jackguo380 / vim-lsp-cxx-highlight

Vim plugin for C/C++/ObjC semantic highlighting using cquery, ccls, or clangd
MIT License
337 stars 26 forks source link

Highlighting gets slow as files grow in size #63

Open MysteriousJ opened 3 years ago

MysteriousJ commented 3 years ago

Highlighting is perfectly fast on small files, but once files get over 500 lines, highlighting noticeably lags for every few characters I type in insert mode. It would be great if there was a way to disable highlighting while typing, or only reapply highlighting on a function call so it could be hooked up to an autocmd.

Configuration:

CoC configuration:

{
    "clangd.semanticHighlighting": true,
    "coc.preferences.hoverTarget": "echo",
    "emitInactiveRegions" : true,
    "diagnostic.enable": false
}

Log from typing in a 1400 line file:

5/7/2021 8:10:11 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:11 PM: hl_symbols (textprop nvim) highlighted 3485 symbols in file src\Entity.h
5/7/2021 8:10:11 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.244072s to complete
5/7/2021 8:10:11 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:12 PM: hl_symbols (textprop nvim) highlighted 3485 symbols in file src\Entity.h
5/7/2021 8:10:12 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.244040s to complete
5/7/2021 8:10:12 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:12 PM: hl_symbols (textprop nvim) highlighted 3485 symbols in file src\Entity.h
5/7/2021 8:10:12 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.241240s to complete
5/7/2021 8:10:12 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:12 PM: hl_symbols (textprop nvim) highlighted 3380 symbols in file src\Entity.h
5/7/2021 8:10:12 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.225770s to complete
5/7/2021 8:10:12 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:12 PM: hl_symbols (textprop nvim) highlighted 3380 symbols in file src\Entity.h
5/7/2021 8:10:12 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.229005s to complete
5/7/2021 8:10:13 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:13 PM: hl_symbols (textprop nvim) highlighted 3380 symbols in file src\Entity.h
5/7/2021 8:10:13 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.236636s to complete
5/7/2021 8:10:13 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:13 PM: hl_symbols (textprop nvim) highlighted 3380 symbols in file src\Entity.h
5/7/2021 8:10:13 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.232892s to complete
5/7/2021 8:10:13 PM: textprop nvim notify symbols for src\Entity.h
5/7/2021 8:10:13 PM: hl_symbols (textprop nvim) highlighted 3380 symbols in file src\Entity.h
5/7/2021 8:10:13 PM: operation hl_symbols (textprop nvim) src\Entity.h took   0.225046s to complete

Log from typing in a 20 line file:

5/7/2021 8:13:12 PM: textprop nvim notify symbols for src\BuildConfig.h
5/7/2021 8:13:12 PM: hl_symbols (textprop nvim) highlighted 6 symbols in file src\BuildConfig.h
5/7/2021 8:13:12 PM: operation hl_symbols (textprop nvim) src\BuildConfig.h took   0.001372s to complete
5/7/2021 8:13:12 PM: textprop nvim notify symbols for src\BuildConfig.h
5/7/2021 8:13:12 PM: textprop nvim notify symbols for src\BuildConfig.h
5/7/2021 8:13:12 PM: stopped hl_symbols timer
5/7/2021 8:13:12 PM: hl_symbols (textprop nvim) highlighted 6 symbols in file src\BuildConfig.h
5/7/2021 8:13:12 PM: operation hl_symbols (textprop nvim) src\BuildConfig.h took   0.001457s to complete
5/7/2021 8:13:13 PM: textprop nvim notify symbols for src\BuildConfig.h
5/7/2021 8:13:13 PM: hl_symbols (textprop nvim) highlighted 6 symbols in file src\BuildConfig.h
5/7/2021 8:13:13 PM: operation hl_symbols (textprop nvim) src\BuildConfig.h took   0.001537s to complete
5/7/2021 8:13:13 PM: textprop nvim notify symbols for src\BuildConfig.h
5/7/2021 8:13:13 PM: hl_symbols (textprop nvim) highlighted 6 symbols in file src\BuildConfig.h
5/7/2021 8:13:13 PM: operation hl_symbols (textprop nvim) src\BuildConfig.h took   0.001419s to complete
jackguo380 commented 2 years ago

Sorry for the late response, not sure if you're still experiencing this or have moved on. But anyways, that is sending a lot of requests. I personally don't use clangd so this slipped by me, the behvavior looks a lot worse.

I have made an initial attempt to address typing. We can't completely ignore updates to the highlighting during editing, but the timer period can be adjusted, if a new request comes in before the timer runs it will reset the timeout. This should result in dramatically fewer highlighting runs, obviously you won't get real-time highlight updates but that's probably fine.

The changes are on a separate branch as they are experimental: feature-mode-delay

These are new settings variables to toggle:

Please try setting this and seeing if your situation improves:

let g:lsp_cxx_hl_use_mode_delay = 1
let g:lsp_cxx_hl_edit_delay_ms = 1000

You can play around with the edit delay to see if you prefer more or less latency.

MysteriousJ commented 2 years ago

I've been using these settings for the past week and they work great! I prefer g:lsp_cxx_hl_delay_ms as it also makes successive normal mode operations smoother.