rust-lang / rust.vim

Vim configuration for Rust.
Apache License 2.0
3.89k stars 295 forks source link

Rustfmt is extremely slow in large files when using nvim-lsp #438

Open maddiemort opened 3 years ago

maddiemort commented 3 years ago

Steps to reproduce:

Expected vs. actual behavior:

Please note a few things:

I'm happy to do any debugging or profiling you'd like me to, but you'll have to let me know what to run in order to do that, because my knowledge of vim really isn't extensive enough for me to know how to do that myself. Thanks!

Paste debugging info from the Rust Vim plugin via one of the following commands: :RustInfo, :RustInfoToClipboard, or :RustInfoToFile <filename>.

``` rust.vim Global Variables: let g:ftplugin_rust_source_path = v:null let g:loaded_syntastic_rust_cargo_checker = v:null let g:loaded_syntastic_rust_filetype = v:null let g:loaded_syntastic_rust_rustc_checker = v:null let g:rust_bang_comment_leader = v:null let g:rust_cargo_avoid_whole_workspace = v:null let g:rust_clip_command = v:null let g:rust_conceal = v:null let g:rust_conceal_mod_path = v:null let g:rust_conceal_pub = v:null let g:rust_fold = v:null let g:rust_last_args = v:null let b:rust_last_args = [] let g:rust_last_rustc_args = v:null let b:rust_last_rustc_args = [] let g:rust_original_delimitMate_excluded_regions = v:null let g:rust_playpen_url = v:null let g:rust_prev_delimitMate_quotes = v:null let g:rust_recent_nearest_cargo_tol = v:null let g:rust_recent_root_cargo_toml = v:null let g:rust_recommended_style = v:null let g:rust_set_conceallevel = v:null let g:rust_set_conceallevel=1 = v:null let g:rust_set_foldmethod = v:null let g:rust_set_foldmethod=1 = v:null let g:rust_shortener_url = v:null let g:rustc_makeprg_no_percent = v:null let g:rustc_path = v:null let g:rustfmt_autosave = 1 let g:rustfmt_autosave_if_config_present = v:null let g:rustfmt_command = 'rustup run nightly-2021-03-01 rustfmt' let g:rustfmt_emit_files = 1 let g:rustfmt_fail_silently = 0 let g:rustfmt_options = '' let g:syntastic_extra_filetypes = ['rust'] let g:syntastic_rust_cargo_fname = v:null rustfmt 1.4.36-nightly (7de6968e 2021-02-07) rustc 1.51.0-nightly (1d0d76f8d 2021-01-24) cargo 1.51.0-nightly (783bc43c6 2021-01-20) NVIM v0.5.0-dev+c1fbc2ddf Build type: Release LuaJIT 2.1.0-beta3 Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210301-91403-1qxibkt/build/config -I/tmp/neovim-20210301-91403-1qxibkt/src -I/usr/local/include -I/usr/local/opt/luv/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210301-91403-1qxibkt/build/src/nvim/auto -I/tmp/neovim-20210301-91403-1qxibkt/build/include Compiled by soren@Rigel.local Features: +acl +iconv +tui See ":help feature-compile" system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-c1fbc2d_1/share/nvim" Run :checkhealth for more info ```
rubdos commented 3 years ago

FWIW, I'm experiencing the same delay with coc-nvim+coc-rust-analyzer.

stsewd commented 3 years ago

Hi, does this patch speed things up https://github.com/rust-lang/rust.vim/pull/448?

amaush commented 3 years ago

@stsewd Found your submitted patch and applied it to my vim-polyglot "rustfmt.vim" file and rustfmt autosave improved from 2.8 secs to 0.8 secs on a file with ~700 lines. Definitely a massive improvement. Thank you!

maddiemort commented 3 years ago

I haven't had the chance to fully test the performance impact of your patch yet @stsewd, but my first impression is that it triggers this issue: neovim/neovim#14645

amaush commented 3 years ago

I managed to reproduce the issue mentioned by @nerosnm by reverting 'nvim_buf_set_lines()' back to 'call_setline()'.

gyscos commented 3 months ago

I think this issue is still present - running :RustFmt here is terribly slow (~10 seconds), while running it separately from the CLI is instantaneous.

Looks like the "fix" PR mentioned above ended up being reverted, probably because it was causing #14645. Is there another workaround?

awused commented 2 months ago

It looks like https://github.com/neovim/neovim/issues/14645 is fixed. I've been manually applying https://github.com/rust-lang/rust.vim/pull/448 for years, but if the underlying neovim bug is fixed maybe it's time to re-merge it? I'll admit, I never noticed the https://github.com/neovim/neovim/issues/14645 bug before nvim 0.10.0, so I'm not the one to say if the behaviour that caused it to be rolled back is truly gone.