prabirshrestha / asyncomplete-buffer.vim

provides buffer autocomplete for asyncomplete.vim
44 stars 15 forks source link

refresh_keywords question #12

Open amadeus opened 5 years ago

amadeus commented 5 years ago

refresh_keywords appears to get called heavily when the cursor moves. This seems a bit of an overkill - and really hurts when viewing larger files. I know there's a max file size - but I'd still like to be able to use the buffer in these larger files without hurting movement.

Perhaps the task for compiling these results could be done asynchronously? Or at least is there a way to disable it on cursor move - when there surely are no new updates?

amadeus commented 5 years ago

I've done a bit more digging, and I think I figured out why performance is so slow on large buffers.

This line: https://github.com/prabirshrestha/asyncomplete-buffer.vim/blob/master/autoload/asyncomplete/sources/buffer.vim#L56

I think the objects are never equal due to the cursor positions and line numbers getting updated on cursor move.

I am not sure the proper fix here, however It looks like something along the lines of comparing the changedtick would be the correct solution? If this is the case, I would be happy to submit a PR for it, just not sure if that's the right fix.

    if a:event == 'TextChangedI'
        call s:refresh_keyword_incr(a:ctx['typed'])
    else
        if s:last_ctx['changedtick'] == a:ctx['changedtick']
            return
        endif
        let s:last_ctx = a:ctx
        call s:refresh_keywords()
    endif