fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16.01k stars 1.45k forks source link

Opening a .go file using vim slows down because of vim-go #3229

Closed suhas-bn-1412 closed 3 years ago

suhas-bn-1412 commented 3 years ago

What did you do? (required: The issue will be closed when not provided)

I installed vim-go plugin and tried to open .go files and it takes a lot of time. Upon inspection, I noticed that sourcing some files related to vim-go plugin is consuming most of the time

image

As you can see the time difference between line 111 and 112, sourcing path.vim (or job.vim I don't exactly know how logs are printed) takes a lot of time

What did you expect to happen?

I expected that the file would open immediately

What happened instead?

It takes more time to open the file

Configuration (MUST fill this out):

vim-go version: latest

vimrc you used to reproduce:

vimrc ```vim " install vim-plug if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source ~/.vimrc endif "------------------------------------------------------------------------------ " Plug installed plugins call plug#begin('~/.vim/plugged') " Golang syntax highlighting, auto completions Plug 'fatih/vim-go' " NERDtree for file browsing Plug 'preservim/nerdtree' " Botton line (vim status bar) Plug 'itchyny/lightline.vim' " Color scheme Plug 'gryf/wombat256grf' call plug#end() "------------------------------------------------------------------------------ " Turn on syntax highlighting syntax on " Backapce should work over everything set backspace=indent,eol,start " Show line numbers set number " tab uses this many spaces set tabstop=8 " Status bar set laststatus=2 " Last line set showmode set showcmd " colorscheme colorscheme wombat256grf " Any vertical splits to happen on right set splitright " Any horizontal splits to happen at bottom set splitbelow "------------------------------------------------------------------------------ " NERDtree nnoremap :NERDTreeToggle nnoremap :NERDTree let g:NERDTreeDirArrowExpandable = '>' let g:NERDTreeDirArrowCollapsible = '^' "------------------------------------------------------------------------------ " lightline -> status bar if !has('gui_running') set t_Co=256 endif let g:lightline = { \ 'colorscheme': 'wombat', \ } "------------------------------------------------------------------------------ "------------------------------------------------------------------------------ " Solve any issues caused by plugins " " " Vim taking time to load " https://stackoverflow.com/questions/14635295/vim-takes-a-very-long-time-to-start-up set clipboard=exclude:.* "------------------------------------------------------------------------------ ```

Vim version (first three lines from :version): VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 8 2021 09:58:42)

Go version (go version): go version go1.13.7 linux/amd64

Go environment

go env Output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/snataraj/.cache/go-build"
GOENV="/home/snataraj/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/snataraj/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/net/wtl-netapp-2/vol/VIEW/swbuild_snap_view/vobs/fw-tools/gitrepos_data/golang_master_2/golang-1.13.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/net/wtl-netapp-2/vol/VIEW/swbuild_snap_view/vobs/fw-tools/gitrepos_data/golang_master_2/golang-1.13.7/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build724252137=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:


(PS: specify how to check gopls version, I'll paste the output)

bhcleek commented 3 years ago

you get can get the version of gopls with gopls version or by using :GoReportGitHubIssue in Vim and copying it from the information populated for you.

suhas-bn-1412 commented 3 years ago

:GoReportGithubIssue won't work as I'm using vim inside ssh session. 'gopls version' didn't work in terminal(-bash: gopls: command not found) or vim(E492: Not an editor command: gopls version)

bhcleek commented 3 years ago

gopls may be in your $GOPATH/bin or $GOBIN directories; it sounds like neither is in your $PATH, so try: $GOBIN/gopls version and $GOPATH/bin/gopls version.

suhas-bn-1412 commented 3 years ago

gopls version: golang.org/x/tools/gopls v0.6.11 golang.org/x/tools/gopls@v0.6.11 h1:7S2k0xuVYc3secjy2uz0n+fGYxGJU6gXsLOmQ/r1HoI=

bhcleek commented 3 years ago

The strange thing here is that job doesn't do much. You can even see in your profile that the time executing code in that file was very small; it's the total duration that took a long time.

Can you add let g:go_debug=['shell-commands'] to your vimrc and duplicate this? I'm curious exactly which command is being executed when you see this delay.

Have you tried using top or other tools to see what's running on your system?

suhas-bn-1412 commented 3 years ago

After adding let g:go_debug=['shell-commands'], I see these are the shell commands that are being run vim-go: shell command: 'go' 'env' 'GOBIN'

bhcleek commented 3 years ago

I suspect there's more than that. You can execute :messages to see them all.

As I mentioned before, I don't think this is vim-go that's the problem. Running using top to see what's taking a while may be helpful for you, too.

suhas-bn-1412 commented 3 years ago

vim-go: shell command: 'go' 'env' 'GOBIN'
vim-go: shell command: 'go' 'env' 'GOPATH'
vim-go: job command: ['/home/snataraj/go/bin/gopls', '-remote=auto']
vim-go: shell command: '/usr/local/fw-tools/Linux/bin/go' 'env' 'GOMOD'
vim-go: shell command: '/usr/local/fw-tools/Linux/bin/go' 'env' 'GOMOD'
vim-go: initializing gopls
vim-go: initialized gopls
This is the complete output of ":messages"

bhcleek commented 3 years ago

Thank you

The good news is that I don't see anything unexpected here. The bad news for you is that I don't see anything that points to a problem in vim-go itself. As I mentioned previously, the original startup profile output shows that the time spent in job.vim is minimal.

The only things I've been able to think of are to:

  1. update your version of Go; your current version is three major versions behind (make sure to do :GoUpdateBinaries afterwards!).
  2. Create a fuller profile so we can see exactly where the duration is being spent. To do this, you'd need to start Vim, but without opening a Go file until the profiling has been setup. Something like this
    :profile start profile.log
    :profile func *
    :profile file *
    " At this point do slow actions (e.g. open a go file).
    :profile pause
    :noautocmd qall!
bhcleek commented 3 years ago

closed for lack of feedback.

avegancafe commented 2 years ago

This is happening for me as well, though I don't see anything off in this profile I don't think?

https://gist.github.com/keyboard-clacker/919ddd0a078673abcfec8480aa20c104


EDIT:

I actually just tried uninstalling my go lsp, looks like it was conflicting with vim-go. Uninstalling my other LSP solved my specific problem.

vegerot commented 2 years ago

I'm having the same issue