Skip to content

lag in vim on saving .ml file #64

@nilsbecker

Description

@nilsbecker

hi, recently i have noticed laggy behavior when editing a small to medium sized dune project in vim. i tried to debug it by using :profile start profile.log , profile func *. i then performed :w then i broke the last line in this function:

    let add_products config =
      let open Config in
      function
      | Empty  -> ()
      | Single m' -> add config m'
      | Pair (m',m'') -> (* inserted line break *)
        add config m'; add config m''

when i then :w again, i get a lag of a few seconds. my final profile.log has the following suspicious section:

FUNCTION  OMLetFoldLevel()
    Defined: ~/.vim/plugins/vim-ocaml/ftplugin/ocaml.vim:176
Called 23281 times
Total time:  17.862757
 Self time:   2.871963

count  total (s)   self (s)
                            
                              " This is for not merging blank lines around folds to them
23281              0.096067   if getline(a:l) !~ '\S'
  805              0.000996     return -1
22476              0.010256   endif
                            
                              " We start folds for modules, classes, and every toplevel definition
22476              0.242120   if getline(a:l) =~ '^\s*\%(\<val\>\|\<module\>\|\<class\>\|\<type\>\|\<method\>\|\<initializer\>\|\<inherit\>\|\<exception\>\|\<external\>\)'
  224              0.001100     exe 'return ">' (indent(a:l)/s:i)+1 '"'
22252              0.011305   endif
                            
                              " Toplevel let are detected thanks to the indentation
22252  15.161066   0.170272   if getline(a:l) =~ '^\s*let\>' && indent(a:l) == s:i+s:topindent(a:l)
 1238              0.007322     exe 'return ">' (indent(a:l)/s:i)+1 '"'
21014              0.010320   endif
                            
                              " We close fold on end which are associated to struct, sig or object.
                              " We use syntax information to do that.
21014              0.145205   if getline(a:l) =~ '^\s*end\>' && synIDattr(synID(a:l, indent(a:l)+1, 0), "name") != "ocamlKeyword"
   39              0.000091     return (indent(a:l)/s:i)+1
20975              0.009617   endif
                            
                              " Folds end on ;;
20975              0.078737   if getline(a:l) =~ '^\s*;;'
   16              0.000060     exe 'return "<' (indent(a:l)/s:i)+1 '"'
20959              0.009870   endif
                            
                              " Comments around folds aren't merged to them.
20959              1.727391   if synIDattr(synID(a:l, indent(a:l)+1, 0), "name") == "ocamlComment"
 4184              0.004404     return -1
16775              0.007958   endif
                            
16775              0.013879   return '='

i don't understand why function should be called that often? this is the function with the biggest time budget in the profile.

i am using ocp-indent and the ALE plugin, where i set

" use ale to fix trailing spaces in ocaml
let g:ale_fixers = {
			\ 'ocaml': ['trim_whitespace', 'remove_trailing_lines' ]
			\}

to trim whitespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions