Skip to content

SwiftPM regresses flutter clean times #183946

Closed

Description

@vashworth

When using SwiftPM, each plugin becomes an Xcode scheme.

When running flutter clean, it iterates through the schemes and cleans each:

for (final String scheme in projectInfo.schemes) {
await xcodeProjectInterpreter.cleanWorkspace(
xcodeWorkspace.path,
scheme,
verbose: _verbose,
);
}

This increases the time it takes for flutter clean to complete. The plugin schemes don't make sense to be built individually and you'd have to do it though Xcode anyways, so I think skipping them is a valid solution.

Activity

  1. added
    platform-iosiOS applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-macosBuilding on or for macOS specifically
    team-iosOwned by iOS platform team
    on Mar 20, 2026
  2. changed the title [-]Skip SwiftPM plugin schemes when doing `flutter clean[/-] [+]Skip SwiftPM plugin schemes when doing `flutter clean`[/+] on Mar 20, 2026
  3. added
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Mar 26, 2026
  4. hellohuanlin commented on Mar 26, 2026

    @hellohuanlin
    Contributor

    @hellohuanlin watch out for local packages if we indeed want to skip cleaning those

  5. vashworth commented on Mar 31, 2026

    @vashworth
    ContributorAuthor

    @jmagman and I discussed this briefly and one potential solution would be to add a build flag (something like --xcode-workspace) and only do the xcodebuild clean if the flag is passed in.

    That would also fix #127708 and #173940

    Another alternative may be to only clean the current scheme based on if a flavor is passed in (or default to Runner). We could also add an --all flag or something

  6. vashworth commented on Apr 28, 2026

    @vashworth
    ContributorAuthor

    How to get the scheme:

    Future<String?> schemeForBuildInfo(BuildInfo buildInfo, {Logger? logger}) async {
    final XcodeProjectInfo? info = await projectInfo();
    if (info == null) {
    logger?.printError('Xcode project info not found.');
    return null;
    }
    final String? scheme = info.schemeFor(buildInfo);
    if (scheme == null) {
    info.reportFlavorNotFoundAndExit();
    }
    return scheme;
    }

  7. okorohelijah commented on Apr 30, 2026

    @okorohelijah
    Contributor

    @vashworth I suggest we clean all application/flavor schemes by default instead of introducing specific --flavor or --all flags. Plus we already have --scheme flag for developers who want to clean a specific flavor

    The primary cause of the slowness during flutter clean is the sequential cleaning of individual SwiftPM plugin schemes, rather than the app's flavor schemes themselves. By simply filtering out the plugin and internal framework schemes from the loop, we can resolve the performance regression entirely while preserving the broad application cleanup developers expect from the command. wdyt?

  8. vashworth commented on Apr 30, 2026

    @vashworth
    ContributorAuthor

    [@vashworth](https://github.com/vashworth) I suggest we clean all application/flavor schemes by default instead of introducing specific --flavor or --all flags. Plus we already have --scheme flag for developers who want to clean a specific flavor

    The primary cause of the slowness during flutter clean is the sequential cleaning of individual SwiftPM plugin schemes, rather than the app's flavor schemes themselves. By simply filtering out the plugin and internal framework schemes from the loop, we can resolve the performance regression entirely while preserving the broad application cleanup developers expect from the command. wdyt?

    That's not always the case. It is for this particular issue, but not for #127708, which was filed before SwiftPM was introduced.

  9. okorohelijah commented on Apr 30, 2026

    @okorohelijah
    Contributor

    @vashworth I agree. This fix directly targets #173940 and #183946, which are caused by the SwiftPM plugin schemes.

    However, it doesn't necessarily address #127708. Fixing #127708 would require skipping the xcodebuild native cleanup by default, which could be a breaking change for developers who rely on it to fix corrupted native caches and it’s unclear how many developers are working exclusively on web-only platforms with no iOS devices installed so I'm not sure if the trade-off of a breaking change is worth it for that specific edge case.

    Maybe a better approach for #127708 would be a separate PR that checks if a build/ios folder exists. If a developer has never built for iOS, we could safely bypass launching the xcodebuild clean step altogether. wdyt

  10. okorohelijah commented on Apr 30, 2026

    @okorohelijah
    Contributor

    @vashworth Plus if the ios or macos isnt being built, the time i assume should be constant maybe 3 -5 seconds which i dont think is worth the breaking change

  11. vashworth commented on Jun 15, 2026

    @vashworth
    ContributorAuthor

    Just skipping the schemes is insufficient:

    https://discord.com/channels/608014603317936148/846507953959862273/1515776742982287500

    Every xcodebuild command triggers SwiftPM dependencies to download. We've filed an issue with Apple about this (FB22283724).

    flutter clean uses xcodebuild -list to get the list of schemes:

    final XcodeProjectInfo projectInfo = (await xcodeProjectInterpreter.getInfo(
    xcodeProject,
    buildDirectory: globals.fs.directory(xcodeProject.darwinPlatform.buildDirectory()),
    ))!;

    And uses xcodebuild clean to actually do the clean:

    Future<void> cleanWorkspace(
    XcodeBasedProject xcodeProject,
    String workspacePath,
    String scheme, {
    required Directory buildDirectory,
    bool verbose = false,
    }) async {
    final String projectPath = _fileSystem.currentDirectory.path;
    final List<String> xcodebuildCommandArgs = await fetchDependenciesAndGenerateXcodebuildArgs(
    xcodeProject,
    buildDirectory,
    );
    await _processUtils.run(<String>[
    ...xcodebuildCommandArgs,
    '-workspace',
    workspacePath,
    '-scheme',
    scheme,
    if (!verbose) '-quiet',
    'clean',
    ...environmentVariablesAsXcodeBuildSettings(_platform),
    ], workingDirectory: projectPath);
    }

    As stated before, a solution would be to add a build flag (something like --xcode-workspace) and only do the xcodebuild clean if the flag is passed in.

  12. okorohelijah commented on Jul 7, 2026

    @okorohelijah
    Contributor

    this is fixed by #186004

  13. changed the title [-]Skip SwiftPM plugin schemes when doing `flutter clean`[/-] [+]SwiftPM regresses `flutter clean` times[/+] on Jul 8, 2026
  14. vashworth commented on Jul 8, 2026

    @vashworth
    ContributorAuthor

    @okorohelijah I don't think this is sufficiently fixed yet, see comment: #183946 (comment)

  15. github-actions commented on Aug 24, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listplatform-iosiOS applications specificallyplatform-macosBuilding on or for macOS specificallyteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions