<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140876>140876</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`Expr::getExprLoc()` is slow
</td>
</tr>
<tr>
<th>Labels</th>
<td>
slow-compile
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
This first came up when the implementation of `CallExpr::getBeginLoc()` was changed and we saw a surprising drop in compile times.
We call `Expr::getExprLoc()` (and various other functions returning a `SourceLocation`) _all the time_. The assumption is that the call is cheap and that it's fine to do even if the source location isn't used in the end.
Changing the implementation of `Expr::getExprLoc()` to just `return SourceLocation()` improves compile times considerably: https://llvm-compile-time-tracker.com/compare.php?from=a71f56d63f569ca0ed543d3d01c684ca6ac7dffd&to=2510892ea46a84a284e0cde9f2a4edae3cdb183d&stat=instructions:u
tl;dr: Up to 15%.
Quick experiment with `callgrind` when compiling `SemaExpr.cpp`:

We should improve this.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyElE-P2zYQxT8NfRnYoEjq30EHb7YGCuRSNEWPwYgcSUwoUeCfdfLtC2q9KbZAk5stDefN-82jMEY7b0QDq59Y_XzCnBYfhjQiGQrhNHrzffi02AiTDTGBxpUg73BfaIO0ENh1d7TSljBZv4GfgDX8Azr327c9MHll8jpTeqLZbh-9ZqJjomcNhztG0AtuMxnAzcCdIOIdEGIOe7DRbjOY4HewG2i_7tYRJLtSvDB-Zfz6N4FG54raO6Xy550QE13p_4LB-hzBp4UCTHnTZd4IgVIOW1HD0utPn4Omj14fdljDmejhcxEqZssAny_waSHAGPO6H55thLRgOiqOmcoTvRDuh7PjnU1MtAXiRpA8GA_0QhvY6TgVD1VwD1mwcWOiTZAjmQKg1NBmHtY_FGxl4v_l_3MiycOXHFMpfHUP_3H9o9Kue_AvFN9vALTfojUUcHTfmbzCktIei564MXFz7mU9Pw6cy4FzCqi_UrhovzJxK68w0GVfdiZvU_Ark8_YVlPdmEZOddNr5GRqJY00vNJNpzQ2qFszTYaJJnkmn0Vd8a4XhKrBTqHoFHFtqJ8EKjJIUpux6mSpjwkTk892iynk160zec2vLJNj8skUWPDXXshUNRP1A_Qf2eqvQN92CrYghrtNS8FWtjwHu5kjyeUqvPotSykhohUL9Yve9xIheX3tx0TF6qffV5yJ1c9MdO_BzTYteXxQypHCGVNCvRTpyMQNY6TjR8P7tprG6cx53ZxVr-oz6m46t0IKpRXvJl2VDfLrj7sSF5-deVsopMUeF-lkBml62eOJhqpVbSdEX6vTMsieplFXNe90V4lRiakehVHY1w3vZWVOdhBc1LwWVcWFkOoilZLUG6Sxb2theqY4rWjdpeTh4sN8sjFmGirFu7Y5ORzJxeOzI0R0_v4WGSZE-RCF4cjRmOfIFHc2pvhvp2STo-GXQbcRSudTDm74CerS9i23e_BfSCcmbse0hfZj4JdB_BMAAP__GvSqJA">