jceb / vim-orgmode

Text outlining and task management for Vim based on Emacs' Org-Mode
http://www.vim.org/scripts/script.php?script_id=3642
Other
3.12k stars 266 forks source link

Duplicate InsertLeave autocmds created, affecting performance in long sessions #223

Closed jdpopkin closed 8 years ago

jdpopkin commented 8 years ago

Hi! Right now, performance declines over time as I leave a single Neovim session open with this plugin activated. In particular, when I enter Normal mode in a .org buffer, the editor freezes for as much as several seconds. Restarting Neovim fixes this problem, but within a few hours a noticeable delay appears again.

The source of these delays appears to be duplicate InsertLeave autocommands - checking the active set with :au InsertLeave showed individual .org buffers with many, many duplicate InsertLeave autocommands.

It looks like this plugin sets up additional InsertLeave autocommands every time a FileType org event happens. In my version of Vim (7.4), those are only fired when a file's type changes, but in Neovim 0.1.2, these are also fired when switching into a buffer of a different filetype. Neovim developers have told me that it's an upstream change and that the same thing happens in more recent versions of Vim, though I have not yet verified this firsthand.

See #222 for my attempt at a fix. Basically, this change creates a buffer-scope variable to record that the InsertLeave autocmd has already been created for this buffer, and avoids creating another InsertLeave autocmd if this variable has already been set.

Awesome plugin, by the way :)

Ron89 commented 8 years ago

Thanks for the reporting and PR. Change merged. :D