Skip to content

Pub workspace loading is ~17x slower for literal paths with Dart 3.11 #4850

Description

@khoadng

Environment

  • Dart SDK 3.12.2 stable on macOS arm64
  • macOS 26.5.2 (25F84)

Problem

After raising a 513-package monorepo's root SDK constraint to Dart 3.12, every package-level dart test invocation started taking roughly 30 seconds before test discovery. Even dart test --help pays the workspace-loading cost. This makes running package tests separately or in parallel prohibitively slow.

The workspace uses literal paths rather than glob patterns:

name: workspace
environment:
  sdk: '>=3.12.0 <4.0.0'
workspace:
  - packages/package_0
  - packages/package_1
  # 510 more literal package paths
  - packages/package_511
  - packages/subject

The following script creates two equivalent 513-member workspaces. The only difference is the root language version.

Save as repro.dart:

import 'dart:io';

void main(List<String> arguments) {
  final output = Directory(arguments[0])..createSync();
  final rootLanguageVersion = arguments[1];
  final workspace = <String>[];

  for (var index = 0; index < 512; index++) {
    final name = 'package_$index';
    final path = 'packages/$name';
    workspace.add(path);
    final directory = Directory('${output.path}/$path')
      ..createSync(recursive: true);
    File('${directory.path}/pubspec.yaml').writeAsStringSync('''
name: $name
publish_to: none
environment:
  sdk: '>=3.10.0 <4.0.0'
resolution: workspace
''');
  }

  workspace.add('packages/subject');
  final subject = Directory('${output.path}/packages/subject')
    ..createSync(recursive: true);
  File('${subject.path}/pubspec.yaml').writeAsStringSync('''
name: subject
publish_to: none
environment:
  sdk: '>=3.10.0 <4.0.0'
resolution: workspace
dev_dependencies:
  test: 1.31.0
''');

  File('${output.path}/pubspec.yaml').writeAsStringSync('''
name: synthetic_workspace
publish_to: none
environment:
  sdk: '>=$rootLanguageVersion.0 <4.0.0'
workspace:
${workspace.map((path) => '  - $path').join('\n')}
''');
}
dart repro.dart fast 3.10
dart repro.dart slow 3.11

(cd fast && dart pub get)
(cd slow && dart pub get)

time sh -c 'cd fast/packages/subject && dart test --help >/dev/null'
time sh -c 'cd slow/packages/subject && dart test --help >/dev/null'

Run each timed command twice to exclude initial snapshot creation.

Expected behavior

The 3.11 workspace should have similar startup time to the otherwise identical 3.10 workspace when all workspace entries are literal paths.

Actual behavior

Warm measurements:

root language 3.10:  0.71 s real
root language 3.11: 11.86 s real

Replacing the 513 literal workspace entries with a single packages/* glob reduces the warm 3.11 run to 0.73 seconds.

The 3.11 run remains slow after the test executable snapshot has been created:

real 11.86
user  3.61
sys   8.48

--verbose output

There is no error output. The command succeeds normally after the startup delay; the slowdown occurs before test discovery or help output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions