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

cmd/gomobile: Use parallel build for frameworks on Apple platforms #74

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

imWildCat
Copy link

@imWildCat imWildCat commented Jan 1, 2022

Currently the build for different targets and CPU architectures is sequential. Even for a small project, it usually takes about one minute to build for -target maccatalyst,ios,iossimulator,macos, which is very different from our perception of build speed of Golang.
By adopting this parallel build approach, we can save a lot of time.

Simple visualization (gomobile bind -target maccatalyst,ios,iossimulator,macos ...):

Main Branch

  1. Build Mac Catalyst (amd64)
  2. Build Mac Catalyst (arm64)
    • Merge into a fat binary
  3. Build iOS (arm64)
  4. Build iOS Simulator (amd64)
  5. Build iOS Simulator (arm64)
    • Merge into a fat binary
  6. Build macOS (amd64)
  7. Build macOS (arm64)
    • Merge into a fat binary
  8. Create xcframework

This PR

  1. Build different architectures in parallel
  2. Merge different architectures for a single target into a fat binary (this is the limitation of xcodebuild. In theory, we don't need to do so. Reference: https://developer.apple.com/forums/thread/666335?answerId=685927022#685927022)
  3. Create xcframework

Quick Benchmark

Local machine comparison with a minimal demo Golang project (on M1 Max):

Sample 1

Official demo: https://github.com/golang/mobile/tree/master/example/bind/hello

# This PR
$ time gomobile-parallel bind -v -target maccatalyst,ios,iossimulator,macos -o /path/to/parallel/Demo.xcframework
gomobile-parallel bind -v -target  -o   29.46s user 18.07s system 303% cpu 15.645 total

# Main Branch
$ time gomobile bind -v -target maccatalyst,ios,iossimulator,macos -o /path/to/sequential/Demo.xcframework
gomobile bind -v -target maccatalyst,ios,iossimulator,macos -o   27.10s user 13.18s system 77% cpu 52.052 total

Sample 2

# This PR
gomobile-parallel bind -target  -o   30.98s user 17.43s system 183% cpu 26.400 total

# Main branch
gomobile bind -target maccatalyst,ios,iossimulator,macos -o   25.80s user 13.17s system 38% cpu 1:42.43 total

@imWildCat imWildCat changed the title Use parallel build for frameworks Use parallel build for frameworks on Apple platforms Jan 1, 2022
@gopherbot
Copy link
Contributor

This PR (HEAD: 7a4f454) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://golang.org/doc/contribute.html#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.


Please don’t reply on this GitHub thread. Visit golang.org/cl/375134.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 0572ebc) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@imWildCat imWildCat marked this pull request as ready for review January 1, 2022 04:23
@gopherbot
Copy link
Contributor

This PR (HEAD: 6e4c23b) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

This PR (HEAD: 45c4267) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

This PR (HEAD: 1b903c7) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

This PR (HEAD: 50d954c) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@imWildCat imWildCat changed the title Use parallel build for frameworks on Apple platforms cmd/gomobile: Use parallel build for frameworks on Apple platforms Jan 7, 2022
cmd/gomobile/bind_iosapp.go Outdated Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Outdated Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Outdated Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Outdated Show resolved Hide resolved
cmd/gomobile/bind_iosapp.go Outdated Show resolved Hide resolved
@gopherbot
Copy link
Contributor

This PR (HEAD: fd0e949) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

This PR (HEAD: faf4e94) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/375134 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@imWildCat
Copy link
Author

@hyangah gentle ping : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants