Skip to content

Enable parallel compilation by splitting targets per architecture - #2097

Merged
okankoAMZ merged 9 commits into
mainfrom
makefile-optim
Apr 24, 2026
Merged

Enable parallel compilation by splitting targets per architecture#2097
okankoAMZ merged 9 commits into
mainfrom
makefile-optim

Conversation

@okankoAMZ

@okankoAMZ okankoAMZ commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Problem

The Makefile builds all architectures sequentially within each platform target. On a multi-core machine, make amazon-cloudwatch-agent-linux took ~75s because amd64 and arm64 binaries were compiled one after the other.

Changes

Split build targets by architecture and enable automatic parallel builds:

  • Add MAKEFLAGS += -j4 for automatic parallelization (4 parallel jobs)
  • Split amazon-cloudwatch-agent-linux into amazon-cloudwatch-agent-linux-amd64 + amazon-cloudwatch-agent-linux-arm64 sub-targets
  • Split amazon-cloudwatch-agent-darwin into amazon-cloudwatch-agent-darwin-amd64 + amazon-cloudwatch-agent-darwin-arm64 sub-targets
  • Add explicit build dependencies to package-prepare-* targets to prevent race conditions

Before

graph TD
 build["make build"]

 build --> linux
 build --> darwin
 build --> windows

 subgraph Linux["⛓️ Linux (sequential — bottleneck)"]
 linux["amazon-cloudwatch-agent-linux"]
 copy_ver1["copy-version-file"]
 workload_linux["workload-discovery-linux"]
 amd64_seq["🔴 Build AMD64<br/>(runs first)"]
 arm64_seq["🔴 Build ARM64<br/>(blocked — waits for AMD64)"]
 linux --> copy_ver1
 linux --> workload_linux
 linux ==> amd64_seq
 amd64_seq ==>|"must finish before"| arm64_seq
 end

 subgraph Darwin["⛓️ Darwin (sequential — bottleneck)"]
 darwin["amazon-cloudwatch-agent-darwin"]
 copy_ver2["copy-version-file"]
 workload_darwin["workload-discovery-darwin"]
 amd64_seq2["🔴 Build AMD64<br/>(runs first)"]
 arm64_seq2["🔴 Build ARM64<br/>(blocked — waits for AMD64)"]
 darwin --> copy_ver2
 darwin --> workload_darwin
 darwin ==> amd64_seq2
 amd64_seq2 ==>|"must finish before"| arm64_seq2
 end

 subgraph Windows
 windows["amazon-cloudwatch-agent-windows"]
 end

 subgraph Packaging["Packaging (no explicit dependencies)"]
 package_rpm["package-prepare-rpm"]
 package_deb["package-prepare-deb"]
 package_win["package-prepare-win-zip"]
 package_darwin_tar["package-prepare-darwin-tar"]
 end

 package_rpm -.no explicit dependency.-> linux
 package_deb -.no explicit dependency.-> linux
 package_win -.no explicit dependency.-> windows
 package_darwin_tar -.no explicit dependency.-> darwin

 style amd64_seq stroke:#ff6b6b,stroke-width:3px
 style arm64_seq stroke:#ff6b6b,stroke-width:3px
 style amd64_seq2 stroke:#ff6b6b,stroke-width:3px
 style arm64_seq2 stroke:#ff6b6b,stroke-width:3px
 style linux stroke:#ffa500,stroke-width:2px
 style darwin stroke:#ffa500,stroke-width:2px
Loading

After

graph LR
 build["make build"]

 subgraph Linux["Linux (parallel)"]
 linux["amazon-cloudwatch-agent-linux"]
 linux_amd64["amazon-cloudwatch-agent-linux-amd64"]
 linux_arm64["amazon-cloudwatch-agent-linux-arm64"]
 copy_ver1["copy-version-file"]
 workload_linux["workload-discovery-linux"]
 linux --> linux_amd64
 linux --> linux_arm64
 linux_amd64 --> copy_ver1
 linux_amd64 --> workload_linux
 linux_arm64 --> copy_ver1
 linux_arm64 --> workload_linux
 end

 subgraph Darwin["Darwin (parallel)"]
 darwin["amazon-cloudwatch-agent-darwin"]
 darwin_amd64["amazon-cloudwatch-agent-darwin-amd64"]
 darwin_arm64["amazon-cloudwatch-agent-darwin-arm64"]
 copy_ver2["copy-version-file"]
 workload_darwin["workload-discovery-darwin"]
 darwin --> darwin_amd64
 darwin --> darwin_arm64
 darwin_amd64 --> copy_ver2
 darwin_amd64 --> workload_darwin
 darwin_arm64 --> copy_ver2
 darwin_arm64 --> workload_darwin
 end

 subgraph Windows
 windows["amazon-cloudwatch-agent-windows"]
 end

 build --> linux
 build --> darwin
 build --> windows

 subgraph Packaging["Packaging (explicit dependencies)"]
 package_rpm["package-prepare-rpm"]
 package_deb["package-prepare-deb"]
 package_win["package-prepare-win-zip"]
 package_darwin_tar["package-prepare-darwin-tar"]
 end

 package_rpm --> linux
 package_deb --> linux
 package_win --> windows
 package_darwin_tar --> darwin

 style linux_amd64 stroke:#51cf66
 style linux_arm64 stroke:#51cf66
 style darwin_amd64 stroke:#51cf66
 style darwin_arm64 stroke:#51cf66
 style linux stroke:#339af0
 style darwin stroke:#339af0
 style package_rpm stroke:#a78bfa
 style package_deb stroke:#a78bfa
 style package_win stroke:#a78bfa
 style package_darwin_tar stroke:#a78bfa
Loading

Tests

Local benchmarks (32-core machine)

Target Before After Speedup
amazon-cloudwatch-agent-linux 74.93s 6.22s 12x
make build (all platforms) ~90s 6.44s ~14x

CI benchmarks (non-cached, vs run #1679)

Job Before After Speedup
BuildAndUpload / MakeBinary 13m 45s 3m 47s 3.6x
BuildAndUploadCN / MakeBinary 15m 9s 4m 9s 3.6x
BuildAndUploadITAR / MakeBinary 13m 55s 5m 23s 2.6x
MakeMacPkg 11m 27s 3m 38s 3.2x

Backwards compatibility

All existing top-level targets (make build, make release, make amazon-cloudwatch-agent-linux, etc.) are preserved — fully backwards compatible.

  builds by splitting targets by architecture

  - Add NPROCS/MAKEFLAGS for automatic parallelization
  - Split linux target into linux-amd64 and linux-arm64
  - Split darwin target into darwin-amd64 and darwin-arm64
  - Add build dependencies to package-prepare-* targets
  - Exclude build-profile* from check_secrets

  Build time improvement: ~12x faster (74s -> 6s for linux)
@okankoAMZ okankoAMZ changed the title Enable parallel Enable parallel compilation by splitting targets per architecture Apr 22, 2026
okankoAMZ added a commit that referenced this pull request Apr 22, 2026
@okankoAMZ okankoAMZ added the ready for testing Indicates this PR is ready for integration tests to run label Apr 22, 2026
jefchien pushed a commit that referenced this pull request Apr 22, 2026
@okankoAMZ
okankoAMZ marked this pull request as ready for review April 23, 2026 15:30
@okankoAMZ
okankoAMZ requested a review from a team as a code owner April 23, 2026 15:30
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Comment thread Makefile
Comment thread Makefile Outdated
Comment thread Makefile Outdated
@okankoAMZ
okankoAMZ merged commit 693f2e4 into main Apr 24, 2026
326 checks passed
@okankoAMZ
okankoAMZ deleted the makefile-optim branch April 24, 2026 15:08
@okankoAMZ
okankoAMZ restored the makefile-optim branch April 24, 2026 15:09
@okankoAMZ
okankoAMZ deleted the makefile-optim branch April 24, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for testing Indicates this PR is ready for integration tests to run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants