Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize hashrocket alignment for speed
The way the function is currently written, it is processing the same lines over and over again, which can make things very slow if we're processing an entire file that is big. In order to optimize what the function is doing, I made puppet#align#AlignHashrockets report back what line indexes it has worked on and then we accumulate the line indexes already seen so that we can skip over them when we encounter those lines again in our loop. As an example of a slow-to-process file, I've found that in https://github.com/puppetlabs/puppetlabs-apache the file manifests/vhosts.pp, which is 2967 lines long was particularly slow to process with the current code. If I open that file with nvim/vim, then go to the first line and reformat the whole file (gggqG), it takes the plugin: nvim 0.9.5: elapsed time: 48.235387 vim 9.1: elapsed time: 76.116376 With the optimization in place, the plugin takes: nvim 0.9.5: elapsed time: 0.101734 vim 9.1: elapsed time: 0.12892 so about two orders of magnitude faster. The above timings were taken with a CPU 12th Gen Intel(R) Core(TM) i5-1240P and 32 Gb of RAM, so your measurements may vary a bit.
- Loading branch information