Giter Site home page Giter Site logo

Comments (11)

dosentmatter avatar dosentmatter commented on July 19, 2024 3

It was slow for me when I open a .md or .js file at the root of my git repo. I'm assuming that is so because it has more parent directories to search before it finds a match.

It also speeds up for me when I comment out vim-polyglot.

I used this method to profile:

This is the slow code in vim-sleuth.

Note that I modified the glob to break it out into multiple lines to see which part is slow

diff --git a/plugin/sleuth.vim b/plugin/sleuth.vim
index 0af4a5d..2acd603 100644
--- a/plugin/sleuth.vim
+++ b/plugin/sleuth.vim
@@ -152,7 +152,10 @@ function! s:detect() abort
   let dir = expand('%:p:h')
   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
     for pattern in patterns
-      for neighbor in split(glob(dir.'/'.pattern), "\n")[0:7]
+      let l:q = glob(dir.'/'.pattern)
+      let l:w = split(l:q, "\n")
+      let l:e = l:w[0:7]
+      for neighbor in l:e
         if neighbor !=# expand('%:p') && filereadable(neighbor)
           call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
           let c -= 1

The following is the profile log of the slow code. It is the slowest by far. It is 6.122388 seconds while the next slowest is 0.474592 seconds.

FUNCTION  <SNR>53_detect()
    Defined: ~/dotfiles/.vim/plugged/vim-sleuth/plugin/sleuth.vim line 140
Called 2 times
Total time:   6.122388
 Self time:   0.014866

count  total (s)   self (s)
    2              0.000005   if &buftype ==# 'help'
                                return
    2              0.000001   endif
                            
    2   0.006688   0.000068   let options = s:guess(getline(1, 1024))
    2   0.000023   0.000014   if s:apply_if_ready(options)
                                return
    2              0.000001   endif
    2              0.000007   let c = get(b:, 'sleuth_neighbor_limit', get(g:, 'sleuth_neighbor_limit', 20))
    2   0.058177   0.000017   let patterns = c > 0 ? s:patterns_for(&filetype) : []
    2              0.000033   call filter(patterns, 'v:val !~# "/"')
    2              0.000083   let dir = expand('%:p:h')
   12              0.000121   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
  120              0.000165     for pattern in patterns
  110   6.052985   0.010418       let l:q = glob(dir.'/'.pattern)
  110              0.001128       let l:w = split(l:q, "\n")
  110              0.000222       let l:e = l:w[0:7]
  118              0.000149       for neighbor in l:e
    8              0.000247         if neighbor !=# expand('%:p') && filereadable(neighbor)
                                      call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
                                      let c -= 1
    8              0.000007         endif
    8   0.000176   0.000114         if s:apply_if_ready(options)
                                      let b:sleuth_culprit = neighbor
                                      return
    8              0.000003         endif
    8              0.000007         if c <= 0
                                      break
    8              0.000003         endif
  118              0.000077       endfor
  110              0.000082       if c <= 0
                                    break
  110              0.000037       endif
  120              0.000055     endfor
   10              0.000036     let dir = fnamemodify(dir, ':h')
   12              0.000037   endwhile
    2              0.000007   if has_key(options, 'shiftwidth')
    2   0.000158   0.000057     return s:apply_if_ready(extend({'expandtab': 1}, options))
                              endif

You can see that the slowest part is 110 6.052985 0.010418 let l:q = glob(dir.'/'.pattern).
ie.

count: 110
total (s): 6.052985
self (s): 0.010418

If I comment out vim-polyglot, it speeds up from 6.122388 seconds to 2.074977 seconds

FUNCTION  <SNR>52_detect()
    Defined: ~/dotfiles/.vim/plugged/vim-sleuth/plugin/sleuth.vim line 140
Called 1 time
Total time:   2.074977
 Self time:   0.006617

count  total (s)   self (s)
    1              0.000003   if &buftype ==# 'help'
                                return
    1              0.000001   endif
                            
    1   0.004010   0.000039   let options = s:guess(getline(1, 1024))
    1   0.000014   0.000008   if s:apply_if_ready(options)
                                return
    1              0.000000   endif
    1              0.000004   let c = get(b:, 'sleuth_neighbor_limit', get(g:, 'sleuth_neighbor_limit', 20))
    1   0.046690   0.000010   let patterns = c > 0 ? s:patterns_for(&filetype) : []
    1              0.000014   call filter(patterns, 'v:val !~# "/"')
    1              0.000044   let dir = expand('%:p:h')
    6              0.000058   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
   50              0.000066     for pattern in patterns
   45   2.022525   0.004882       let l:q = glob(dir.'/'.pattern)
   45              0.000390       let l:w = split(l:q, "\n")
   45              0.000086       let l:e = l:w[0:7]
   48              0.000055       for neighbor in l:e
    3              0.000097         if neighbor !=# expand('%:p') && filereadable(neighbor)
                                      call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
                                      let c -= 1
    3              0.000002         endif
    3   0.000053   0.000034         if s:apply_if_ready(options)
                                      let b:sleuth_culprit = neighbor
                                      return
    3              0.000001         endif
    3              0.000002         if c <= 0
                                      break
    3              0.000001         endif
   48              0.000023       endfor
   45              0.000030       if c <= 0
                                    break
   45              0.000014       endif
   50              0.000022     endfor
    5              0.000017     let dir = fnamemodify(dir, ':h')
    6              0.000021   endwhile
    1              0.000003   if has_key(options, 'shiftwidth')
    1   0.000069   0.000028     return s:apply_if_ready(extend({'expandtab': 1}, options))
                              endif

You can see that the slowest part is 45 2.022525 0.004882 let l:q = glob(dir.'/'.pattern).
ie.

count: 45
total (s): 2.022525
self (s): 0.004882

Looks like it is called less often when disabling vim-polyglot - from 110 to 45.


Since it calls globs so many more times, I added an echom to log out the patterns it is using to glob. I'm thinking the while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0 or for pattern in patterns loop wrapping the glob loops many more times when vim-polyglot is on for some reason.

diff --git a/plugin/sleuth.vim b/plugin/sleuth.vim
index 0af4a5d..1be7a24 100644
--- a/plugin/sleuth.vim
+++ b/plugin/sleuth.vim
@@ -152,7 +152,11 @@ function! s:detect() abort
   let dir = expand('%:p:h')
   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
     for pattern in patterns
-      for neighbor in split(glob(dir.'/'.pattern), "\n")[0:7]
+      echom dir.'/'.pattern
+      let l:q = glob(dir.'/'.pattern)
+      let l:w = split(l:q, "\n")
+      let l:e = l:w[0:7]
+      for neighbor in l:e
         if neighbor !=# expand('%:p') && filereadable(neighbor)
           call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
           let c -= 1

messages with vim-polyglot enabled has 55 lines:

/Users/kevin/workspace/project/repository/*.js
/Users/kevin/workspace/project/repository/*.javascript
/Users/kevin/workspace/project/repository/*.es
/Users/kevin/workspace/project/repository/*.mjs
/Users/kevin/workspace/project/repository/*.js
/Users/kevin/workspace/project/repository/*jsx
/Users/kevin/workspace/project/repository/*.{es6,es6.js}
/Users/kevin/workspace/project/repository/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/repository/Jakefile
/Users/kevin/workspace/project/repository/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/repository/Jakefile
/Users/kevin/workspace/project/*.js
/Users/kevin/workspace/project/*.javascript
/Users/kevin/workspace/project/*.es
/Users/kevin/workspace/project/*.mjs
/Users/kevin/workspace/project/*.js
/Users/kevin/workspace/project/*jsx
/Users/kevin/workspace/project/*.{es6,es6.js}
/Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/Jakefile
/Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/Jakefile
/Users/kevin/workspace/*.js
/Users/kevin/workspace/*.javascript
/Users/kevin/workspace/*.es
/Users/kevin/workspace/*.mjs
/Users/kevin/workspace/*.js
/Users/kevin/workspace/*jsx
/Users/kevin/workspace/*.{es6,es6.js}
/Users/kevin/workspace/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/Jakefile
/Users/kevin/workspace/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/Jakefile
/Users/kevin/*.js
/Users/kevin/*.javascript
/Users/kevin/*.es
/Users/kevin/*.mjs
/Users/kevin/*.js
/Users/kevin/*jsx
/Users/kevin/*.{es6,es6.js}
/Users/kevin/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/Jakefile
/Users/kevin/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/Jakefile
/Users/*.js
/Users/*.javascript
/Users/*.es
/Users/*.mjs
/Users/*.js
/Users/*jsx
/Users/*.{es6,es6.js}
/Users/*.{js,mjs,cjs,jsm,es,es6}
/Users/Jakefile
/Users/*.{js,mjs,cjs,jsm,es,es6}
/Users/Jakefile

messages with vim-polyglot disabled has 45 lines:

/Users/kevin/workspace/project/repository/*.js
/Users/kevin/workspace/project/repository/*.javascript
/Users/kevin/workspace/project/repository/*.es
/Users/kevin/workspace/project/repository/*.mjs
/Users/kevin/workspace/project/repository/*.js
/Users/kevin/workspace/project/repository/*jsx
/Users/kevin/workspace/project/repository/*.{es6,es6.js}
/Users/kevin/workspace/project/repository/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/repository/Jakefile
/Users/kevin/workspace/project/*.js
/Users/kevin/workspace/project/*.javascript
/Users/kevin/workspace/project/*.es
/Users/kevin/workspace/project/*.mjs
/Users/kevin/workspace/project/*.js
/Users/kevin/workspace/project/*jsx
/Users/kevin/workspace/project/*.{es6,es6.js}
/Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/project/Jakefile
/Users/kevin/workspace/*.js
/Users/kevin/workspace/*.javascript
/Users/kevin/workspace/*.es
/Users/kevin/workspace/*.mjs
/Users/kevin/workspace/*.js
/Users/kevin/workspace/*jsx
/Users/kevin/workspace/*.{es6,es6.js}
/Users/kevin/workspace/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/workspace/Jakefile
/Users/kevin/*.js
/Users/kevin/*.javascript
/Users/kevin/*.es
/Users/kevin/*.mjs
/Users/kevin/*.js
/Users/kevin/*jsx
/Users/kevin/*.{es6,es6.js}
/Users/kevin/*.{js,mjs,cjs,jsm,es,es6}
/Users/kevin/Jakefile
/Users/*.js
/Users/*.javascript
/Users/*.es
/Users/*.mjs
/Users/*.js
/Users/*jsx
/Users/*.{es6,es6.js}
/Users/*.{js,mjs,cjs,jsm,es,es6}
/Users/Jakefile

$ diff -u polyglot_disabled polyglot_enabled:

$ diff -u polyglot_disabled polyglot_enabled
--- polyglot_disabled	2020-06-07 13:39:10.000000000 -0700
+++ polyglot_enabled	2020-06-07 13:39:10.000000000 -0700
@@ -7,6 +7,8 @@
 /Users/kevin/workspace/project/repository/*.{es6,es6.js}
 /Users/kevin/workspace/project/repository/*.{js,mjs,cjs,jsm,es,es6}
 /Users/kevin/workspace/project/repository/Jakefile
+/Users/kevin/workspace/project/repository/*.{js,mjs,cjs,jsm,es,es6}
+/Users/kevin/workspace/project/repository/Jakefile
 /Users/kevin/workspace/project/*.js
 /Users/kevin/workspace/project/*.javascript
 /Users/kevin/workspace/project/*.es
@@ -16,6 +18,8 @@
 /Users/kevin/workspace/project/*.{es6,es6.js}
 /Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6}
 /Users/kevin/workspace/project/Jakefile
+/Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6}
+/Users/kevin/workspace/project/Jakefile
 /Users/kevin/workspace/*.js
 /Users/kevin/workspace/*.javascript
 /Users/kevin/workspace/*.es
@@ -25,6 +29,8 @@
 /Users/kevin/workspace/*.{es6,es6.js}
 /Users/kevin/workspace/*.{js,mjs,cjs,jsm,es,es6}
 /Users/kevin/workspace/Jakefile
+/Users/kevin/workspace/*.{js,mjs,cjs,jsm,es,es6}
+/Users/kevin/workspace/Jakefile
 /Users/kevin/*.js
 /Users/kevin/*.javascript
 /Users/kevin/*.es
@@ -34,6 +40,8 @@
 /Users/kevin/*.{es6,es6.js}
 /Users/kevin/*.{js,mjs,cjs,jsm,es,es6}
 /Users/kevin/Jakefile
+/Users/kevin/*.{js,mjs,cjs,jsm,es,es6}
+/Users/kevin/Jakefile
 /Users/*.js
 /Users/*.javascript
 /Users/*.es
@@ -43,3 +51,5 @@
 /Users/*.{es6,es6.js}
 /Users/*.{js,mjs,cjs,jsm,es,es6}
 /Users/Jakefile
+/Users/*.{js,mjs,cjs,jsm,es,es6}
+/Users/Jakefile

Notice that when vim-polyglot is enabled, *.{js,mjs,cjs,jsm,es,es6} and Jakefile get duplicated for each directory eg. /Users/kevin/workspace/project/*.{js,mjs,cjs,jsm,es,es6} appears twice.

Even when vim-polyglot is disabled, *.js is already duplicated. This might be from me accidentally having duplicate syntax plugins.


If I modify vim-sleuth to filter out *.{js,mjs,cjs,jsm,es,es6}, with vim-polyglot enabled, the slow function drops to 2.257099 seconds.

diff --git a/plugin/sleuth.vim b/plugin/sleuth.vim
index 0af4a5d..feaacb6 100644
--- a/plugin/sleuth.vim
+++ b/plugin/sleuth.vim
@@ -152,7 +152,14 @@ function! s:detect() abort
   let dir = expand('%:p:h')
   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
     for pattern in patterns
-      for neighbor in split(glob(dir.'/'.pattern), "\n")[0:7]
+      if pattern == '*.{js,mjs,cjs,jsm,es,es6}'
+        continue
+      endif
+      echom dir.'/'.pattern
+      let l:q = glob(dir.'/'.pattern)
+      let l:w = split(l:q, "\n")
+      let l:e = l:w[0:7]
+      for neighbor in l:e
         if neighbor !=# expand('%:p') && filereadable(neighbor)
           call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
           let c -= 1
FUNCTION  <SNR>53_detect()
    Defined: ~/dotfiles/.vim/plugged/vim-sleuth/plugin/sleuth.vim line 140
Called 2 times
Total time:   2.257099
 Self time:   0.012863

count  total (s)   self (s)
    2              0.000005   if &buftype ==# 'help'
                                return
    2              0.000001   endif
                            
    2   0.006897   0.000074   let options = s:guess(getline(1, 1024))
    2   0.000027   0.000015   if s:apply_if_ready(options)
                                return
    2              0.000001   endif
    2              0.000009   let c = get(b:, 'sleuth_neighbor_limit', get(g:, 'sleuth_neighbor_limit', 20))
    2   0.055799   0.000018   let patterns = c > 0 ? s:patterns_for(&filetype) : []
    2              0.000039   call filter(patterns, 'v:val !~# "/"')
    2              0.000165   let dir = expand('%:p:h')
   12              0.000142   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
  120              0.000113     for pattern in patterns
  110              0.000145       if pattern == '*.{js,mjs,cjs,jsm,es,es6}'
   20              0.000015         continue
   90              0.000034       endif
   90              0.000629       echom dir.'/'.pattern
   90   2.190129   0.008628       let l:q = glob(dir.'/'.pattern)
   90              0.000601       let l:w = split(l:q, "\n")
   90              0.000138       let l:e = l:w[0:7]
   94              0.000104       for neighbor in l:e
    4              0.000210         if neighbor !=# expand('%:p') && filereadable(neighbor)
                                      call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
                                      let c -= 1
    4              0.000002         endif
    4   0.000052   0.000032         if s:apply_if_ready(options)
                                      let b:sleuth_culprit = neighbor
                                      return
    4              0.000002         endif
    4              0.000003         if c <= 0
                                      break
    4              0.000002         endif
   94              0.000047       endfor
   90              0.000061       if c <= 0
                                    break
   90              0.000029       endif
  100              0.000042     endfor
   10              0.000035     let dir = fnamemodify(dir, ':h')
   12              0.000024   endwhile
    2              0.000008   if has_key(options, 'shiftwidth')
    2   0.000164   0.000067     return s:apply_if_ready(extend({'expandtab': 1}, options))
                              endif

You can see 90 2.190129 0.008628 let l:q = glob(dir.'/'.pattern) drops down from 110 calls to 90 calls. Not as few as the 45 with vim-polyglot disabled, but still around 2 seconds.


If filter out duplicates withfilter(copy(patterns), 'index(patterns, v:val, v:key+1)==-1'), it speeds up to 4.097402 seconds

diff --git a/plugin/sleuth.vim b/plugin/sleuth.vim
index 0af4a5d..1ece818 100644
--- a/plugin/sleuth.vim
+++ b/plugin/sleuth.vim
@@ -151,8 +151,12 @@ function! s:detect() abort
   call filter(patterns, 'v:val !~# "/"')
   let dir = expand('%:p:h')
   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
-    for pattern in patterns
-      for neighbor in split(glob(dir.'/'.pattern), "\n")[0:7]
+    for pattern in filter(copy(patterns), 'index(patterns, v:val, v:key+1)==-1')
+      echom dir.'/'.pattern
+      let l:q = glob(dir.'/'.pattern)
+      let l:w = split(l:q, "\n")
+      let l:e = l:w[0:7]
+      for neighbor in l:e
         if neighbor !=# expand('%:p') && filereadable(neighbor)
           call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
           let c -= 1
FUNCTION  <SNR>53_detect()
    Defined: ~/dotfiles/.vim/plugged/vim-sleuth/plugin/sleuth.vim line 140
Called 2 times
Total time:   4.097402
 Self time:   0.012806

count  total (s)   self (s)
    2              0.000004   if &buftype ==# 'help'
                                return
    2              0.000001   endif
                            
    2   0.005848   0.000060   let options = s:guess(getline(1, 1024))
    2   0.000020   0.000012   if s:apply_if_ready(options)
                                return
    2              0.000001   endif
    2              0.000006   let c = get(b:, 'sleuth_neighbor_limit', get(g:, 'sleuth_neighbor_limit', 20))
    2   0.054298   0.000015   let patterns = c > 0 ? s:patterns_for(&filetype) : []
    2              0.000034   call filter(patterns, 'v:val !~# "/"')
    2              0.000128   let dir = expand('%:p:h')
   12              0.000108   while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0
   90              0.000499     for pattern in filter(copy(patterns), 'index(patterns, v:val, v:key+1)==-1')
   80              0.000612       echom dir.'/'.pattern
   80   4.032894   0.008493       let l:q = glob(dir.'/'.pattern)
   80              0.000754       let l:w = split(l:q, "\n")
   80              0.000142       let l:e = l:w[0:7]
   84              0.000099       for neighbor in l:e
    4              0.000266         if neighbor !=# expand('%:p') && filereadable(neighbor)
                                      call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep')
                                      let c -= 1
    4              0.000003         endif
    4   0.000078   0.000049         if s:apply_if_ready(options)
                                      let b:sleuth_culprit = neighbor
                                      return
    4              0.000002         endif
    4              0.000003         if c <= 0
                                      break
    4              0.000001         endif
   84              0.000042       endfor
   80              0.000054       if c <= 0
                                    break
   80              0.000024       endif
   90              0.000037     endfor
   10              0.000034     let dir = fnamemodify(dir, ':h')
   12              0.000024   endwhile
    2              0.000007   if has_key(options, 'shiftwidth')
    2   0.000154   0.000068     return s:apply_if_ready(extend({'expandtab': 1}, options))
                              endif

80 4.032894 0.008493 let l:q = glob(dir.'/'.pattern).

It went from 6.122388 seconds to 4.032894 seconds. Duplicate *.js and. *.{js,mjs,cjs,jsm,es,es6} were filtered out.

When I previously filtered all of *.{js,mjs,cjs,jsm,es,es6} (vim-polyglot enabled), it dropped to 2.257099 seconds. If I only filter out duplicates, it jumps to 4.032894 seconds.

This still doesn't really explain anything about vim-polyglot to me. We should probably be filtering out duplicates, but something in vim-polyglot is making it slow. I don't know how vim-polyglot could affect speed of globing for files.

With the duplicate filter on, disabling vim-polyglot drops the glob from 80 4.032894 0.008493 let l:q = glob(dir.'/'.pattern) to 40 2.130007 0.004161 let l:q = glob(dir.'/'.pattern).

The only difference I see is called 80 instead of 40 times, even with duplicate filtering on.

from vim-sleuth.

docwhat avatar docwhat commented on July 19, 2024 2

I worked around this problem by creating an ftplugin/markdown.vim file in my configs and putting this in it:

let b:sleuth_automatic = 0

I can still run :Sleuth manually if I really need it, but markdown files should always have a shiftwidth of 4. Anything else doesn't "work".

from vim-sleuth.

alecdwm avatar alecdwm commented on July 19, 2024 1

To note: the issue can be reproduced by replacing vim-polyglot just vim-markdown.

Until the underlying cause is found, I've been using vim-pandoc-syntax instead of vim-markdown by adding it to my .vimrc along with:

let g:polyglot_disabled = ['markdown']
augroup pandoc_syntax
	au! BufNewFile,BufFilePre,BufRead *.md set filetype=markdown.pandoc
augroup END

Update:

I no longer use this workaround.
I've instead replaced it with a method of lazy loading vim-sleuth unless the filetype is markdown:

call plug#begin('~/.vim/plugged')

" load vim-polyglot
Plug '[email protected]:sheerun/vim-polyglot.git' " lots of languages

" lazy-load vim-sleuth in the indefinite future
Plug '[email protected]:tpope/vim-sleuth.git', { 'on': [] } " smart indent recognition

call plug#end()

" load vim-sleuth if filetype is not markdown
autocmd Filetype * if &filetype != 'markdown' | call plug#load('vim-sleuth') | endif

from vim-sleuth.

dylan-chong avatar dylan-chong commented on July 19, 2024

@alecdwm vim-pandoc-syntax looks like it isn't very well maintained - no commits in one year and seventy two issues! how have you been finding that plugin? has it been really buggy or do you still use it

from vim-sleuth.

alecdwm avatar alecdwm commented on July 19, 2024

@dylan-chong I still use vim-pandoc-syntax, and it still works around the long startup time issue in many cases, but there are still some instances in which it also has the long startup time issue.
However, I have not yet been able to narrow down the difference between which markdown files cause the long startup issue and which do not.
As for bugs with vim-pandoc-syntax itself, I haven't run into any yet!

from vim-sleuth.

dylan-chong avatar dylan-chong commented on July 19, 2024

from vim-sleuth.

alecdwm avatar alecdwm commented on July 19, 2024

@dylan-chong Thanks for mentioning the vim-plug lazy load feature!
With that, I've been able to throw this together:

call plug#begin('~/.vim/plugged')

" load vim-polyglot
Plug '[email protected]:sheerun/vim-polyglot.git' " lots of languages

" lazy-load vim-sleuth in the indefinite future
Plug '[email protected]:tpope/vim-sleuth.git', { 'on': [] } " smart indent recognition

call plug#end()

" load vim-sleuth if filetype is not markdown
autocmd Filetype * if &filetype != 'markdown' | call plug#load('vim-sleuth') | endif

Unfortunately, it still doesn't help for the case where I open a non-markdown file, then proceed to open a markdown file in the same session.

from vim-sleuth.

rstacruz avatar rstacruz commented on July 19, 2024

The ftdetect workaround described in this comment above works for me today (thanks @docwhat).

from vim-sleuth.

sheerun avatar sheerun commented on July 19, 2024

vim-polyglot has now its own, heavily optimized version of vim-sleuth that prevents this plugin from loading, so this can be closed now. for all changes you can see this file: https://github.com/sheerun/vim-polyglot/blob/master/plugin/polyglot.vim

from vim-sleuth.

docwhat avatar docwhat commented on July 19, 2024

Here is a fixed version of @sheerun's link: sheerun/vim-polyglot/ftdetect/polyglot.vim

from vim-sleuth.

tpope avatar tpope commented on July 19, 2024

If I modify vim-sleuth to filter out *.{js,mjs,cjs,jsm,es,es6}, with vim-polyglot enabled, the slow function drops to 2.257099 seconds.

Bizarrely, Vim implements globs with {} in them by shelling out. This will be an order of magnitude slower in the best case scenario, and outright unbearable if you've done something silly like set shellcmdflag=-ic, because now every call will require parsing your .bashrc. I'd encourage anyone experiencing slowness to remove any shell options from their vimrc and try again.

I'm pushing a change to remove duplicates from the pattern list. Between that, the shell config advice, and other changes made since this issue was opened 4 years ago, I think enough progress has been made to close this issue. Anyone who finds the results unsatisfactory is welcome to report back.

vim-polyglot has now its own, heavily optimized version of vim-sleuth

One of these optimizations was to combine all globs into one {} mega-glob, which will most definitely be worse for some users due to involvement of the shell.

that prevents this plugin from loading

If you want to steal and butcher my code, fine, but disabling the plugin you stole it from is unacceptable. Please remove the let g:loaded_sleuth = 1 guard and rename any collisions with the official plugin, including SleuthIndicator().

from vim-sleuth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.