<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104562>104562</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MIPS] `MIPSELFObjectWriter::sortRelocs()` makes compilation near-unusably slow for O32
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alexrp
</td>
</tr>
</table>
<pre>
Building and running the Zig standard library tests (with LLVM 18.1.8):
```console
❯ time zig4 build -j8 -Dno-lib -Dno-bin -fqemu test-std -Dtest-target-filter=mips64- -Dtest-target-filter=mips64el-
________________________________________________________
Executed in 209.15 secs fish external
usr time 18.17 mins 361.00 micros 18.17 mins
sys time 1.02 mins 64.00 micros 1.02 mins
❯ time zig4 build -j8 -Dno-lib -Dno-bin -fqemu test-std -Dtest-target-filter=mips- -Dtest-target-filter=mipsel- -Dtest-slow-targets
________________________________________________________
Executed in 66.50 mins fish external
usr time 242.35 mins 5.87 millis 242.35 mins
sys time 1.06 mins 0.30 millis 1.06 mins
```
As a result of this, we've had to disable MIPS O32 tests for local development and only run them in CI.
Attaching a debugger made it clear that the overwhelming majority of time is spent in `MIPSELFObjectWriter::sortRelocs()`. Specifically (and perhaps unsurprisingly) here:
https://github.com/llvm/llvm-project/blob/ef6760116fa2fa21f78e7a3b499f77e1a3eb7b92/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp#L468-L476
Some extra context:
```
(gdb) p Relocs.size()
$3 = 1412282
(gdb) p Remainder.size()
$4 = 439999
(gdb) p Sorted.size()
$5 = 1019010
```
We build the standard library tests as one big executable so we end up with a ton of relocations. Due to the size of the resulting LLVM IR, I can't easily post it here. :slightly_frowning_face:
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VV9v66gT_TTkZWTL4H_xQx56b26kSq360-1Pe6V9qbAZ23QxeAE3TT_9CpL-3bZS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