Skip to content

windows-latest runner's g++ first compilation is extremely slow and unstable(4s to 60s) #14096

@ZnPdCo

Description

@ZnPdCo

Description

When using the g++ compiler on the windows-latest GitHub Actions runner to compile a simple C++ program, the first compilation time is highly unstable (4s to 60s). The second and third compilations in the same job are consistently under 1 second.

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 22.04
  • Ubuntu 24.04
  • Ubuntu Slim
  • macOS 14
  • macOS 14 Arm64
  • macOS 15
  • macOS 15 Arm64
  • macOS 26
  • macOS 26 Arm64
  • Windows Server 2022
  • Windows Server 2025
  • Windows Server 2025 with Visual Studio 2026

Image version and build link

I will provide more infomations below.

Is it regression?

idk

Expected behavior

I hope that windows-latest runner's g++ first compile should be fast.

Actual behavior

It is very slow and unstable.

Repro steps

The C++ source code compiled is as follows:

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int f(int n) {
	vector<int> a(1);
	for (int i = 0; i < n; i++) {
		a[i] = 100;
	}
}
int *p;
int main() {
	int s;
	cin >> s;
	switch (s) {
		case 1:
			cout << "AC" << endl;
			break;
		case 2:
			cout << "WA" << endl;
			break;
		case 3:
			for (int i = 0; i < 200; i++)
				p = new int[1 << 24], memset(p, 0x3f, sizeof(int) * (1 << 24));
			break;
		case 4:
			while (1)
				;
			break;
		case 5:
			f(100);
			break;
		default:
			break;
	}
}

It should be noted that although the code contains a function with no return statement, we only compile it, not execute it.

The CI workflow (including the C++ source code) can be found here:

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/blob/c3b734815e56a5115b714fba15d10c3063797ab4/.github/workflows/test.yml

Example run output:

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/actions/runs/25832441342/job/75900199272

In that run, compilation took 11 seconds. Attached below are a few more extreme cases.

Image Image Image

Next I tried adding -ftime-report (https://github.com/ZnPdCo/windows-ci-gcc-compile-test/blob/dd5f131ea30de0438f86ebe3d387c415fdc5c7c0/.github/workflows/test.yml) and obtained:

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/actions/runs/25833002457/job/75902175044

In this run, we reached an extreme compilation time of 60 seconds (1st: 61557.9172 ms). The log file includes timestamps for each command. From these timestamps we observed:

  • cc1plus.exe started, but its first version information was printed only 18.5 seconds later. This 18.5 seconds is not accounted for in -ftime-report.
  • The TOTAL wall time reported by -ftime-report was 30.19 seconds, broken down as:
    • phase setup: 5.36 s
    • phase parsing: 11.88 s
    • phase opt and generate: 12.86 s
    • preprocessing: 8.06 s
    • callgraph functions expansion: 8.60 s
  • Additionally:
    • as.exe: 0.54 s
    • collect2.exe: 7.33 s

We have tried disabling Windows Defender (although according to the official repo it should already be disabled by default). This did not improve the first compilation speed at all. The second link below provides evidence that Defender is indeed disabled by default.

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/blob/2bf29752f3df3afa16691f1112512a7505d6a1d9/.github/workflows/test.yml

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/actions/runs/25833408494/job/75903332461

Switching to the windows-2025-vs2026 runner, the first compilation time stabilised at 5–8 seconds.

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/blob/cd2ee615f3ac08645f909b812220cf9316eb2976/.github/workflows/test.yml

https://github.com/ZnPdCo/windows-ci-gcc-compile-test/actions/runs/25832535087/job/75900585355

It should be noted that I cannot be certain whether the issue is truly resolved on windows-2025-vs2026 (I can only judge by running multiple times to see if the time fluctuates significantly).

Summary: The first-time g++ compilation performance on windows-latest is very poor and unstable, and disabling Windows Defender does not help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions