pangloss / vim-javascript

Vastly improved Javascript indentation and syntax support in Vim.
http://www.vim.org/scripts/script.php?script_id=4452
3.79k stars 358 forks source link

Laggy indent performance on large objects #1174

Closed amadeus closed 4 years ago

amadeus commented 5 years ago

I've attached a gist to use as an example

https://gist.github.com/amadeus/139a4a8d711a18444b0699bdea2ea27c

If you put your cursor on line 6001, and press o to jump into insert mode on a new line, it will be a bit laggy. If you press enter a few times while in insert mode, you get even more lag.

Is there a way we can optimize this use case @bounceme?

bounceme commented 5 years ago

i'm looking into it! this definetly needs a fix

bounceme commented 5 years ago

so the offending function is here: https://github.com/pangloss/vim-javascript/blob/master/indent/javascript.vim#L290

the reason so far as i can tell is that it cant find the opening brace of the object before the timeout here: https://github.com/pangloss/vim-javascript/blob/master/indent/javascript.vim#L395 so it wants to find the start of a continued expression and the loop in isContOne runs like 6000 times

bounceme commented 5 years ago

so basically just need to limit the looping in that function. will fix soon

bounceme commented 5 years ago

also limiting the looping will prevent the time lag, but it will probably make the indent incorrect, which is a tradeoff well worth it in these unusual spots

amadeus commented 5 years ago

I know nothing about how indentation works - but is it possible it could just grab the syntax group it's in - and just match from there?

I.E. if it's in a jsObject and the previous line ends on a comma - match the current indent or something?

bounceme commented 5 years ago

you just gave me an idea.... basically a short circuit to get indent in objects really easily. i'll be working on this