bullets.vim icon indicating copy to clipboard operation
bullets.vim copied to clipboard

Performance hit in completing numbered list

Open ElectrifyPro opened this issue 4 years ago • 9 comments

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.

ElectrifyPro avatar May 01 '21 22:05 ElectrifyPro

Could you share a sample file here?

harshad1 avatar Jun 08 '21 17:06 harshad1

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.

ElectrifyPro avatar Jun 09 '21 01:06 ElectrifyPro

Thanks.

Could you check if let g:bullets_renumber_on_change = 0 improves the performance?

harshad1 avatar Jun 09 '21 16:06 harshad1

Yes, setting that option to 0 does indeed fix the delay.

ElectrifyPro avatar Jun 10 '21 03:06 ElectrifyPro

The issue here is that parse_bullet

  1. Does a lot of work
  2. 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.

harshad1 avatar Jun 12 '21 05:06 harshad1

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.

harshad1 avatar Jun 18 '21 04:06 harshad1

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?

ElectrifyPro avatar Jun 18 '21 15:06 ElectrifyPro

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

harshad1 avatar Jun 18 '21 16:06 harshad1

Unfortunately there still is a delay

Any improvement though?

No, there isn't any noticeable improvement as far as I can tell

ElectrifyPro avatar Jun 19 '21 05:06 ElectrifyPro