complete() function - does it force a redraw of every window?

12 views
Skip to first unread message

Ben Jackson

unread,
Aug 20, 2022, 10:55:50 AM8/20/22
to vim...@googlegroups.com
Hi Bram,

I have been investigating some pathological performance problems with YouCompleteMe (YCM). YCM is a vim plugin which, in effect calls complete() on every keystroke in insert mode. I have noticed that sometimes, vim can become extremely slow while typing in this scenario.

I did some profiling with callgrind and found that 99% of the time was redrawing, and in particular syntax highlighting regex code. Of course, doing something very often makes it appear “slow”.

Anyway, my solution has been to reduce the number of times I call complete(), but I’m still curious if this can be improved. I’m not super clear on the exact set of calls here, but looking at the code it _appears_ that we force a redraw of all windows whenever the pum is undisplayed (pum_undisplay calls redraw_all_later(UPD_NOT_VALID), which is called by set_completion, via ins_compl_free, etc.).

I think this also happens when any key is pressed while the pum is displayed (however it is displayed).

Am I understanding the behaviour correctly - that a full redraw is requested whenever the pum is visible and a key is pressed, or complete() is called?
Is there a way this redraw can be reduced? I seem to recall that popup windows have a clever way to minimise the redraw by storing what they are obscuring (or did I imagine that?).

I’m may have some time/impetus to work on this if it’s a plausible direction.

Cheers,
Ben

Bram Moolenaar

unread,
Aug 20, 2022, 2:24:37 PM8/20/22
to vim...@googlegroups.com, Ben Jackson
If a popup window is closed, moved or resized, the windows under it are
updated with UPD_NOT_VALID. The window contents (with text and
attributes) isn't cached, it needs to be recomputed. Normally this is
fast enough, but with complex syntax highlighting it can be a bit slow.

Caching the text and attributes under the popup might be possible, but
it is tricky. Especially with completion, some text might be put in the
line (which is removed again when not using the completion) which
requires redrawing text around it. The caching only helps in limited
situations.

What would help in general is to make syntax highlighting faster. At
least avoid bottlenecks.


--
CRONE: Who sent you?
ARTHUR: The Knights Who Say Ni!
CRONE: Aaaagh! (she looks around in rear) No! We have no shrubberies here.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ben Jackson

unread,
Aug 20, 2022, 3:04:22 PM8/20/22
to Bram Moolenaar, vim...@googlegroups.com
I wonder if it would be possible to record the window ids of the windows overlapped by the completion pum and only redraw those with NOT_VALID rather than all of them?

> On 20 Aug 2022, at 19:24, Bram Moolenaar <Br...@moolenaar.net> wrote:
>
> 

Bram Moolenaar

unread,
Aug 20, 2022, 4:54:50 PM8/20/22
to vim...@googlegroups.com, Ben Jackson

> I wonder if it would be possible to record the window ids of the
> windows overlapped by the completion pum and only redraw those with
> NOT_VALID rather than all of them?

Yes, if you are careful computing those windows (with status line and
vertical separator). It won't help much if the window that is slow to
redraw still needs updating.

--
Did you ever stop to think... and forget to start again?
-- Steven Wright
Reply all
Reply to author
Forward
0 new messages