Skip to content

Too many await statements in one method triggers exponential build time  #61948

Open
@gwynne

Description

@gwynne

Describe the bug
Since Swift 5.6 and continuing through the present, when a function containing more than ~100-150 independent uses of await is compiled in Xcode, the runtime for the swift-frontend invocation which includes the appropriate file increases extremely rapidly for each additional use of await - for a method with ~200 awaits, the build time reached over 20 minutes.

The method exhibiting this behavior in my direct experience was a test method in an XCTestCase, belonging to a test target in an SPM package. I have not had a chance to verify whether the problem is specific to test methods, nor to narrow down a repro case. From the investigations I have had a chance to make, the problem appears to be during the coroutine splitting pass and seems related to a considerable amount of repeated copying of instances of an LLVM container type.

Moving the implementation of the method in question into three private methods invoked sequentially was sufficient to reduce the build time to a bit under 20 seconds. I have not yet been able to look into it further.

Steps To Reproduce
Steps to reproduce the behavior:

  1. N/A

Expected behavior
Reasonable build time.

Environment (please fill out the following information)

  • OS: macOS Monterey
  • Xcode Version/Tag/Branch: Xcode 14.0 - 14.1 and some versions of 13.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    async & awaitFeature → concurrency: asynchronous function aka the async/await patternbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresperformance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions