<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61064>61064</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Modules] Increased build times across translation units
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          koplas
      </td>
    </tr>
</table>

<pre>
    Given the following translation units:

```C++
export module a;

export namespace a {
 int a_0() {return 0;}
    int a_1() {return 0;}
    int a_2() {return 0;}
...
    int a_1000000() {return 0;}
}
```

```C++

export module b;
import a;

export namespace b {
    int b() {
        return 1;
 }
}
```

```C++
export module c;
import b;

export namespace c {
    int c() {
        return b::b();
 }
}
```

And running the following:
```Bash
echo "Building a.cppm"
time clang++ -std=c++20 --precompile a.cppm -o a.pcm
time clang++ -std=c++20 a.cppm -c -o a.o
echo "Building b.cppm"
time clang++ -std=c++20 -fprebuilt-module-path=. --precompile b.cppm -o b.pcm
time clang++ -std=c++20 -fprebuilt-module-path=. b.cppm -c -o b.o
echo "Building c.cppm"
time clang++ -std=c++20 -fprebuilt-module-path=. --precompile c.cppm -o c.pcm
time clang++ -std=c++20 -fprebuilt-module-path=. c.cppm -c -o c.o
```

Results in this output:
```
Building a.cppm

real    0m25,961s
user 0m24,515s
sys     0m1,337s

real    1m23,304s
user 1m20,309s
sys     0m2,856s

Building b.cppm

real 0m2,201s
user    0m1,978s
sys     0m0,220s

real 0m5,779s
user    0m5,373s
sys     0m0,400s

Building c.cppm

real    0m2,146s
user    0m1,957s
sys 0m0,187s

real    0m5,714s
user    0m5,317s
sys 0m0,389s
```

As expected the build times of a.cppm is high. However, even the build of c.cppm takes a lot of time.
Note that in the precompiling phase of b.cppm and c.cppm circa 200 ms is spent in `WriteAst`, despite not having many lines of code.

[build-times-test.zip](https://github.com/llvm/llvm-project/files/10853435/build-times-test.zip)

</pre>
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