Code Monkey home page Code Monkey logo

Comments (6)

pqn avatar pqn commented on August 23, 2024

In #63 I eliminate an OffsetToPosition call: 7838269#diff-5127272f84a6dcfaad20fe14dc66437f542846b096fd7c41cdc9817a9ee23aacL145

However, locally testing, seems like the rendering is still slow. I'm not sure what work in the function is still O(N) though. I'm assuming you still experience the slowdown as well?

function! s:RenderCurrentCompletion() abort
call s:ClearCompletion()
redrawstatus
if mode() !~# '^[iR]' || (v:false && pumvisible())
return ''
endif
let current_completion = s:GetCurrentCompletionItem()
if current_completion is v:null
return ''
endif
let parts = get(current_completion, 'completionParts', [])
let idx = 0
let inline_cumulative_cols = 0
let diff = 0
for part in parts
let row = get(part, 'line', 0) + 1
if row != line('.')
call codeium#log#Warn('Ignoring completion, line number is not the current line.')
continue
endif
if part.type ==# 'COMPLETION_PART_TYPE_INLINE'
let _col = inline_cumulative_cols + len(get(part, 'prefix', '')) + 1
let inline_cumulative_cols = _col - 1
else
let _col = len(get(part, 'prefix', '')) + 1
endif
let text = part.text
if (part.type ==# 'COMPLETION_PART_TYPE_INLINE' && idx == 0) || part.type ==# 'COMPLETION_PART_TYPE_INLINE_MASK'
let completion_prefix = get(part, 'prefix', '')
let completion_line = completion_prefix . text
let full_line = getline(row)
let cursor_prefix = strpart(full_line, 0, col('.')-1)
let matching_prefix = 0
for i in range(len(completion_line))
if i < len(full_line) && completion_line[i] ==# full_line[i]
let matching_prefix += 1
else
break
endif
endfor
if len(cursor_prefix) > len(completion_prefix)
" Case where the cursor is beyond the completion (as if it added text).
" We should always consume text regardless of matching or not.
let diff = len(cursor_prefix) - len(completion_prefix)
elseif len(cursor_prefix) < len(completion_prefix)
" Case where the cursor is before the completion.
" It could just be a cursor move, in which case the matching prefix goes
" all the way to the completion prefix or beyond. Then we shouldn't do
" anything.
if matching_prefix >= len(completion_prefix)
let diff = matching_prefix - len(completion_prefix)
else
let diff = len(cursor_prefix) - len(completion_prefix)
endif
endif
if has('nvim') && diff > 0
let diff = 0
endif
" Adjust completion. diff needs to be applied to all inline parts and is
" done below.
if diff < 0
let text = completion_prefix[diff :] . text
elseif diff > 0
let text = text[diff :]
endif
endif
if has('nvim')
let _virtcol = virtcol([row, _col+diff])
let data = {'id': idx + 1, 'hl_mode': 'combine', 'virt_text_win_col': _virtcol - 1}
if part.type ==# 'COMPLETION_PART_TYPE_INLINE_MASK'
let data.virt_text = [[text, s:hlgroup]]
elseif part.type ==# 'COMPLETION_PART_TYPE_BLOCK'
let lines = split(text, "\n", 1)
if empty(lines[-1])
call remove(lines, -1)
endif
let data.virt_lines = map(lines, { _, l -> [[l, s:hlgroup]] })
else
continue
endif
call add(s:nvim_extmark_ids, data.id)
call nvim_buf_set_extmark(0, nvim_create_namespace('codeium'), row - 1, 0, data)
else
if part.type ==# 'COMPLETION_PART_TYPE_INLINE'
call prop_add(row, _col + diff, {'type': s:hlgroup, 'text': text})
elseif part.type ==# 'COMPLETION_PART_TYPE_BLOCK'
let text = split(part.text, "\n", 1)
if empty(text[-1])
call remove(text, -1)
endif
for line in text
call prop_add(row, 0, {'type': s:hlgroup, 'text_align': 'below', 'text': line})
endfor
endif
endif
let idx = idx + 1
endfor
endfunction

from codeium.vim.

klew avatar klew commented on August 23, 2024

I just tested it and now it take some time to load suggestions, but once response is ready, I can quickly switch between suggestions. So at least this part is fixed.

When Codeium is enabled on large file, I still see some slowness (short blocking) when I just type. It's probably related to remaining call which calculates cursor_offset - codeium#util#PositionToOffset('.', '.')

Maybe you could consider adding to language server API, ability to provide line numer + column, instead of absolute offset in whole string? This should remove dependency to this O(N) funciton completely.

from codeium.vim.

klew avatar klew commented on August 23, 2024

I just checked accepting suggestion, and it has the same long delay.

from codeium.vim.

pqn avatar pqn commented on August 23, 2024

I've made some optimizations in #69, curious to see how your case behaves now.

from codeium.vim.

klew avatar klew commented on August 23, 2024

It is at least few times faster. Thanks!

from codeium.vim.

pqn avatar pqn commented on August 23, 2024

Great, I'll close this for now. One other place which is still O(N) is assembling the full document from the lines. Not sure if that's avoidable though -- in at least Neovim the buffer is stored as an array of lines according to this Reddit comment.

from codeium.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.