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/mobile: gomobile bind slow compilation #54770

Closed
NightBlaze opened this issue Aug 30, 2022 · 7 comments
Closed

x/mobile: gomobile bind slow compilation #54770

NightBlaze opened this issue Aug 30, 2022 · 7 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@NightBlaze
Copy link

What version of Go are you using (go version)?

$ go version go1.19 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/go/pkg/mod"
GONOPROXY="gitlab.mycompany.com"
GONOSUMDB="gitlab.mycompany.com"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPRIVATE="gitlab.mycompany.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7v/1f7g4jw1337ggmqlxxgq74g00000gn/T/go-build1457147379=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

time gomobile bind -target=ios golang.org/x/mobile/example/bind/hello
30,61s user 16,19s system 118% cpu 39,495 total

What did you expect to see?

Faster compilation

What did you see instead?

30 s compilation time on default empty project. Working project compiles 2,5 minutes

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Aug 30, 2022
@gopherbot gopherbot added this to the Unreleased milestone Aug 30, 2022
@changkun
Copy link
Member

It might be possible that the slow compilation is caused by cgo.

Have you tried rebuilding the project? What's the compilation time?

@heschi heschi added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 30, 2022
@heschi
Copy link
Contributor

heschi commented Aug 30, 2022

cc @hyangah

@NightBlaze
Copy link
Author

@changkun The time is the same for every compilation. It seems that cgo doesn't use any cache and rebuild everything every time.

The same issue (long time compilation of gomobile bind) have all my team members.

@changkun
Copy link
Member

changkun commented Sep 2, 2022

I think https://go-review.googlesource.com/c/mobile/+/426274 is currently speeding up the compilation process. Can this patch mitigate this issue?

@hajimehoshi
Copy link
Member

I'll work on the same thing for iOS in another CL.

@changkun changkun removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 28, 2022
@gopherbot
Copy link

Change https://go.dev/cl/437035 mentions this issue: cmd/gomobile: clean-up the code using gobind for iOS

gopherbot pushed a commit to golang/mobile that referenced this issue Oct 10, 2022
This CL cleans up the code using gobind by these fixes:

- Run the gobind command for each platform, instead of each target (=
  platform + arch).
- Run the gobind command in parallel with errgroup.Group.

This CL doesn't improve performance significantly, but should improve
readability by splitting the long for-range loop.

Updates golang/go#54770

Change-Id: I881810b95db0fa6a6d17982154591af467f1ebfe
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/437035
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Changkun Ou <mail@changkun.de>
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
@gopherbot
Copy link

Change https://go.dev/cl/442195 mentions this issue: cmd/gomobile: concurrent build for iOS archive files

gopherbot pushed a commit to golang/mobile that referenced this issue Oct 20, 2022
This change makes building archive files for iOS concurrent for each
architecture and each platform. The strategy is basically the same as
my previous CL for Android: https://go.dev/cl/426274.

This change also specifies GOMODCACHE explicitly when executing Go
commands so that the existing cache is always used. The default
GOMODCACHE is $GOPATH/pkg/mod, and this path varies when a temporary
GOPATH is specified, which results in cold cache.

Before this change (on my MacBook Pro 2020):

$ time go run ./cmd/gomobile/ bind -target ios ./example/bind/hello/

real    0m23.274s
user    0m15.751s
sys     0m10.469s

After this change:

$ time go run ./cmd/gomobile/ bind -target ios ./example/bind/hello/

real    0m8.059s
user    0m13.763s
sys     0m9.004s

Updates golang/go#37902
Updates golang/go#54770

Change-Id: Iaeb077b58c22ab63d28f78972a0af76660883a05
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/442195
Reviewed-by: Changkun Ou <mail@changkun.de>
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
@golang golang locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
None yet
Development

No branches or pull requests

6 participants