<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60693>60693</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Generating .o file for module takes time proportional to unused code in imported modules
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following two translation units:
```cpp
export module a;
constexpr bool f() {
for (unsigned n = 0; n != 1'000'000; ++n) {
}
return true;
}
template<typename>
struct s {
static constexpr auto a = f();
static constexpr auto b = f();
static constexpr auto c = f();
static constexpr auto d = f();
};
template struct s<int>;
template struct s<long>;
```
```cpp
export module b;
import a;
```
After calling `clang++ -std=c++20 --precompile -x c++-module -c a.cpp -o a.pcm` I would expect module `b` should be compiled very quickly. Instead, I see
```
time clang++ -std=c++20 -fmodule-file=a=a.pcm --precompile -x c++-module -c b.cpp -o b.pcm
________________________________________________________
Executed in 13.09 millis fish external
usr time 3.69 millis 594.00 micros 3.09 millis
sys time 9.42 millis 157.00 micros 9.26 millis
```
which is reasonable, but
```
time clang++ -c b.pcm -o b.o
________________________________________________________
Executed in 5.45 secs fish external
usr time 5.44 secs 677.00 micros 5.44 secs
sys time 0.01 secs 177.00 micros 0.01 secs
```
which is not reasonable. This time scales linearly with the number of explicit template instantiations in `module a`.
This is as of 9f2014269ad8e4f5dc4567ca12919c6135e62f16, but I have experienced this slowness in any version that supports modules.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vs1yozgQfhr50mVKSPyYA4dxPJnKfe9bQjRGO0JiJRHbb78lwMRJZacmW7VUgsH99_XX7W4J79XZINYkP5L8tBNT6K2rW_GqWh-swV1j21v9Q72igdAjdFZre1HmDOFiIThhvBZBWQOTUcET_o3QE6H3e0GXPzmOyzd4Ha0LMNh20giC8OOjvrTGB7yODhprNXSEHQirgJSbVtVZB4QdJj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