Performance hit in completing numbered list
I have a .txt file that has a section in the middle with this format (the list is 30-ish entries long):
...
10. Title 10
• example
• example
• example
• example
11. Title 11
• example
• example
• example
• example
12. Title 12
...
When I place my cursor on the line 12. Title 12 and press o, there is a ~1 second pause before the next 13. line is added. However, when I remove all the lines with • example and repeat the two above steps, there is no pause. I found that the more • example lines that I add in between a numbered entry, the pause gets worse and worse.
Could you share a sample file here?
Here's the repository that has the example: https://github.com/ElectrifyPro/cautious-spoon
There's two files, culprit.txt contains the problem that I showed above. If you put your cursor on any numbered line and press o, there is a delay before the next line is added.
normal.txt is culprit.txt, but with all the items in between each numbered entry removed. There aren't any problems with that file.
Thanks.
Could you check if let g:bullets_renumber_on_change = 0 improves the performance?
Yes, setting that option to 0 does indeed fix the delay.
The issue here is that parse_bullet
- Does a lot of work
- Is called 2x for every element of the list
Having to parse each bullet 2x when walking the list is pretty normal. Improving the performance of parse bullet is what will help here.
I have a PR to help address this here: https://github.com/dkarter/bullets.vim/pull/107
Would you be able to check if it helps your case? You'll likely have to add my clone as an origin and checkout my branch.
Unfortunately there still is a delay when I tried your fix on culprit.txt. Just to make sure I did it correctly, this is what I put in vimrc:
"Plug 'dkarter/bullets.vim'
Plug 'harshad1/bullets.vim', {'branch': 'performance_improvements'}
Also is it necessary for parse_bullet to be called 2x for every list item? Would it not work properly if it was only called once?
Unfortunately there still is a delay
Any improvement though?
Also is it necessary for parse_bullet to be called 2x for every list item?
Technically, no. But in general you need to walk to the top of the list and then back to the bottom. I am looking at strategies to address this. Reducing the calls to parse_bullet would likely yield the greatest performance improvement
Unfortunately there still is a delay
Any improvement though?
No, there isn't any noticeable improvement as far as I can tell