Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: high cpu usage when make changes in package which have some cgo package dependents #50151

Open
zhuah opened this issue Dec 14, 2021 · 4 comments

Comments

@zhuah
Copy link

@zhuah zhuah commented Dec 14, 2021

gopls version

Build info

golang.org/x/tools/gopls v0.7.3
golang.org/x/tools/gopls@v0.7.3 h1:Lru57ht8vtDMouRskFC085VAjBAZRAISd/lwvwOOV0Q=
github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sys@v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/text@v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/tools@v0.1.8-0.20211014194737-fc98fb2abd48 h1:hk7xRoeg0CG1nRLsd5BZLDUgVpA9bnKylGk1p2/BPH0=
golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=

go env

What did you do?

I'm work on a monorepo with some cgo packages in VSCode, when i modify the core package that cgo packages depends on, the cpu usage goes 100%.
I have tried inspect it with

pstree `pgrep gopls`

which shows that there are several clang process created by go list and cgo command.

i must run pkill clang instantly when cpu usage goes 100%, but when i am keep editing, the cpu goes 100% again.
so i'm wondering that is there a way to disable cgo in gopls or let gopls do not compile cgo package.

What did you expect to see?

What did you see instead?

-+- 00827 zhuah /Users/zhuah/go/bin/gopls -mode=stdio
 \-+- 15602 zhuah go list -modfile=TMPDIR/go.5c768b47e65a0399512ae86c5ba9023517f92436988adbfe6f37ff2addbfa6cc.1607909778.mod -mod=readonly -overlay=TMPDIR/gopackages-2412941141/overlay.json -e -json -compiled=true -test=true -export=false -deps=true -find=false -- PACKAGELIST
   |-+- 15634 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b300/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b300/ -g -O2 CGOFILE CGODIR CGOFILE CGOFILE
   | \-+- 15831 zhuah /usr/bin/clang -w -Wno-error -oTMPDIR/go-build833139357/b300//_cgo_.o -gdwarf-2 -c -ferror-limit=0 -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Qunused-arguments -fno-builtin -I TMPDIR/go-build833139357/b300/ -arch x86_64 -m64 -fno-lto -O0 -fdiagnostics-color=never -I . TMPDIR/cgo-gcc-input-2621109915.c
   |   \--- 15833 zhuah /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cgo-gcc-input-2621109915.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -target-linker-version 609 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I TMPDIR/go-build833139357/b300/ -I . -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O0 -Wno-error -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -w -fdebug-compilation-dir CGODIR -ferror-limit 0 -fmessage-length 0 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fno-builtin -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fmax-type-align=16 -fdiagnostics-show-option -o TMPDIR/go-build833139357/b300//_cgo_.o -x c TMPDIR/cgo-gcc-input-2621109915.c
   |-+- 15650 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b096/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b096/ -g -O2 -x objective-c CGOFILE
   | \-+- 15808 zhuah /usr/bin/clang -w -Wno-error -oTMPDIR/go-build833139357/b096//_cgo_.o -gdwarf-2 -c -ferror-limit=0 -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Qunused-arguments -fno-builtin -I TMPDIR/go-build833139357/b096/ -x objective-c -arch x86_64 -m64 -fno-lto -O0 -fdiagnostics-color=never -I . TMPDIR/cgo-gcc-input-556442778.c
   |   \--- 15811 zhuah /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cgo-gcc-input-556442778.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -target-linker-version 609 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I TMPDIR/go-build833139357/b096/ -I . -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O0 -Wno-error -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -w -fdebug-compilation-dir CGODIR -ferror-limit 0 -fmessage-length 0 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fno-builtin -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fobjc-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -o TMPDIR/go-build833139357/b096//_cgo_.o -x objective-c TMPDIR/cgo-gcc-input-556442778.c
   |-+- 15656 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b083/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b083/ -g -O2 -Wno-int-to-pointer-cast CGOFILE
   | \-+- 15801 zhuah (clang)
   |   \--- 15802 zhuah (clang)
   |-+- 15657 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b126/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b126/ -g -O2 -x objective-c -ICGOPACKAGE -Wno-deprecated-declarations CGOFILE
   | \-+- 15659 zhuah (clang)
   |   \--- 15665 zhuah (clang)
   |-+- 15677 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b137/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b137/ -g -O2 -x objective-c CGOFILE
   | \-+- 15681 zhuah (clang)
   |   \--- 15684 zhuah (clang)
   |-+- 15746 zhuah /usr/bin/clang++ -I CGODIR -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=TMPDIR/go-build833139357/b100=/tmp/go-build -gno-record-gcc-switches -fno-common -I TMPDIR/go-build833139357/b100/ -g -O2 -std=c++2a -fno-exceptions -fno-rtti -o TMPDIR/go-build833139357/b100/_x003.o -c CPPFILE
   | \--- 15748 zhuah /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CPPFILE -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 609 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I CGODIR -I TMPDIR/go-build833139357/b100/ -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O2 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -std=c++2a -fdeprecated-macro -fdebug-compilation-dir CGODIR -fdebug-prefix-map=TMPDIR/go-build833139357/b100=/tmp/go-build -ferror-limit 19 -fmessage-length 0 -pthread -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fno-rtti -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-implicit-modules -fobjc-runtime=macosx-10.15.0 -fmax-type-align=16 -fno-common -fno-caret-diagnostics -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o TMPDIR/go-build833139357/b100/_x003.o -x c++ CPPFILE
   |-+- 15773 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b138/ -importpath CGOPACKAGE -- -I TMPDIR/go-build833139357/b138/ -g -O2 -x objective-c CGOFILE CGOFILE
   | \-+- 15779 zhuah /usr/bin/clang -E -dM -arch x86_64 -m64 -I TMPDIR/go-build833139357/b138/ -O2 -x objective-c -I . TMPDIR/cgo-gcc-input-2816487396.c
   |   \--- 15781 zhuah /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cgo-gcc-input-2816487396.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I TMPDIR/go-build833139357/b138/ -I . -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O2 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdebug-compilation-dir CGODIR -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fobjc-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -vectorize-loops -vectorize-slp -dM -o - -x objective-c TMPDIR/cgo-gcc-input-2816487396.c
   \-+- 15803 zhuah /usr/local/Cellar/gotip/pkg/tool/darwin_amd64/cgo -objdir TMPDIR/go-build833139357/b075/ -importpath IMPORTPATH -- -I TMPDIR/go-build833139357/b075/ -g -O2 -Wno-deprecated-declarations -x objective-c CGOFILE
     \-+- 15810 zhuah /usr/bin/clang -w -Wno-error -oTMPDIR/go-build833139357/b075//_cgo_.o -gdwarf-2 -c -ferror-limit=0 -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Qunused-arguments -fno-builtin -I TMPDIR/go-build833139357/b075/ -Wno-deprecated-declarations -x objective-c -arch x86_64 -m64 -fno-lto -O0 -fdiagnostics-color=never -I . TMPDIR/cgo-gcc-input-1994762254.c
       \--- 15813 zhuah /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cgo-gcc-input-1994762254.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -target-linker-version 609 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I TMPDIR/go-build833139357/b075/ -I . -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O0 -Wno-error -Wno-unknown-warning-option -Wno-unneeded-internal-declaration -Wno-unused-function -Wno-deprecated-declarations -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -w -fdebug-compilation-dir CGODIR -ferror-limit 0 -fmessage-length 0 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fno-builtin -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-10.15.0 -fobjc-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -o TMPDIR/go-build833139357/b075//_cgo_.o -x objective-c TMPDIR/cgo-gcc-input-1994762254.c

Editor and settings

Logs

@gopherbot gopherbot added this to the Unreleased milestone Dec 14, 2021
@zhuah
Copy link
Author

@zhuah zhuah commented Dec 14, 2021

I have compiled a modified version of gopls with cgo disabled:
comment -compiled=true option at https://github.com/golang/tools/blob/master/go/packages/golist.go#L812 and
force SetUsesCgo function to return false at https://github.com/golang/tools/blob/master/internal/typesinternal/types.go#L16

it may better to add a command line option -disable-cgo to gopls.

@hyangah
Copy link
Contributor

@hyangah hyangah commented Dec 14, 2021

Thanks for the investigation and experiment @zhuah

I wonder what's breaking when cgo is completely disabled. (related to #35721)
It sounds like your are ok with completely disabling cgo. Does it mean that the cgo packages aren't in your active working set of packages?

@findleyr we have multiple cgo related issues (e.g. #43560) and I don't know where we are. what do you think about keeping track of cgo functionality & performance improvement under an uber issue?

@zhuah
Copy link
Author

@zhuah zhuah commented Dec 15, 2021

I wonder what's breaking when cgo is completely disabled. (related to #35721)

There are still an issue could not import C (no required module provides package "C") on the import "C" statement.
I have tried but couldn't solve it.

Does it mean that the cgo packages aren't in your active working set of packages?

Yes, but even for cgo packages, it's also acceptable for me without cgo type checking, just like GoLand.

It sounds like your are ok with completely disabling cgo.

Yes, it's already good enough for me. Also, after disabled cgo, there are large improvement of setting workspace speed.

@hyangah hyangah removed this from the Unreleased milestone Dec 16, 2021
@hyangah hyangah added this to the gopls/on-deck milestone Dec 16, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Jan 4, 2022

This needs to be further investigated, but probably won't make the v0.7.5 milestone. Moving to v0.8.0.

@findleyr findleyr removed this from the gopls/on-deck milestone Jan 4, 2022
@findleyr findleyr added this to the gopls/v0.8.0 milestone Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants