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

Extreme compilation time penalty for large OpenAPI-generated file on Linux #67214

Open
gwynne opened this issue Jul 11, 2023 · 7 comments
Open
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@gwynne
Copy link
Contributor

gwynne commented Jul 11, 2023

Description
In a project containing a 15,400-line source file generated by the swift-openapi-generator package, a release build takes ~3m 10s on macOS, but performing an identical build in Docker on the same machine (with Docker configured to be able to use all available CPUs and RAM) using the swiftlang/swift:nightly-5.9-jammy image (see below for version specifics) takes ~16m 30s, a penalty of almost 5x. The difference is even more severe using a swift:5.8-amazonlinux2 Intel image (almost 22 minutes). top and ps show that this is not a linker-related issue; a swift-frontend instance is the long-running process. The process spends practically all of its runtime maxing out a single core, with all other cores sitting idle, and uses less than 10% of available RAM; there is no issue of resource exhaustion.

Steps to reproduce

  1. git clone https://github.com/vapor/penny-bot.git && cd penny-bot
  2. git checkout 2d46427d30d9c3868a50bd6b586fe73db0967c5b
  3. swift build -c release --target GHHooksLambda

Expected behavior
The compile time on Linux should be reasonable.

Environment

  • macOS Ventura 13.4.1 (22F82), Xcode 15.0 beta 3 (15A5195k), swift-driver version: 1.85 Apple Swift version 5.9 (swiftlang-5.9.0.120.7 clang-1500.0.34.3)
  • Docker Desktop for Mac 4.21.1 (114176), image swiftlang/swift:nightly-5.9-jammy, tag swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-09-a, Swift version 5.9-dev (LLVM edfa23b742ff932, Swift 4895334e52a9f08)
@gwynne gwynne added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jul 11, 2023
@tomerd
Copy link
Contributor

tomerd commented Jul 11, 2023

cc @MaxDesiatov @al45tair @artemcm

@al45tair al45tair self-assigned this Jul 12, 2023
@al45tair
Copy link
Contributor

Seems pretty reproducible here (Mac finished in a bit over 3m; Linux is still going…). I'll see if I can work out where the time is going.

@al45tair
Copy link
Contributor

I don't have my Linux VM configured with the same exact number of CPUs as the base machine, as the base system has hyper threading, but it took 22m, which is 7x the macOS figure…

@al45tair
Copy link
Contributor

OK, we think this problem is happening in the LLVM optimizer. As a workaround, maybe try adding -Xllvm -vectorize-slp=false to the arguments handed to the Swift compiler.

@al45tair
Copy link
Contributor

I've raised rdar://112463849 internally to track the underlying problem.

@gwynne
Copy link
Contributor Author

gwynne commented Jul 18, 2023

@al45tair Thanks for the update! I can confirm that adding -Xllvm -vectorize-slp=false reduced the total build time on Linux (5.9-jammy nightly, tag swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-10-a) down to a touch under 6m, or about a 3x improvement.

@MahdiBM
Copy link

MahdiBM commented Jul 18, 2023

about a 3x improvement.

Pretty much the same on GitHub CI / Amazon Linux 2 too. About 34/5/6 -> 12/13 minutes. 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

4 participants