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

    <tr>
        <th>Summary</th>
        <td>
            LLVM's SHA256 is very inefficient
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld:MachO
      </td>
    </tr>

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

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

<pre>
    I was able to make ld64.lld 20% (!) faster by tweaking how it computes SHA256.

1. The current SHA256 API requires putting the 32-byte result on the stack and the memcpy()ing it to the right place. Tweaking the API to have an outparam would save this.
2. The SHA256 internals aren't very optimized. Using e.g. `CommonCrypto/CommonDigest.h` on macOS is faster. (17% speedup)
3. (We don't parallelize the SHA256 implementation. Doing that helps a bit more (20%)

https://github.com/nico/llvm-project/commits/hash has details, proof-of-concept level.

I used the repro file at https://drive.google.com/file/d/1wWCeDWQ3OAyVwadyCdFZ0WXNB11ADnBK/view?usp=sharing as benchmark case.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9k1FvmzAQxz8NeTkVgQmkeeAhTVStWrtu6tZMezP2AV4NZrZJxD79zpB2qiZNIijn_9n3u_-ZysipvIMzd8ArjeANdPwFQctiHWstgSURyyFi1xFLI7aFmjuPFqoJ_Bn5i-obaM0ZlAdhumH06ODpw47lRRwlhyjZLe80hq8tghitxd5fMmD3-Q4s_hqVpV2014fTPOVl7KqaPJLoRu3B9POq81y8AO_lHHXYiWGawbZhHxEQfFCsaloPg-YCqewrZVBCQUpq-QnpHDCjH7jlHZzNSK26sOxb5S7obIG-wKqe-u65JqOoh4htPJzQTmAGrzr1G2UM31wohHETQ1Qke9N1pt_bafAmYrdLeFANOh-3pIe2Oi4en0C5i61xMDrdBMfdgCjHgZpbYLJZOyJIsxQP5FqjptJzb6-Y3aCxI5O5V6aP4WCW5rmHFvVA9FCRVZ2xGA6cx_tWZHm33g8uynYETU-jfDtWMU2Xgl6J0IvWp-5qsOYnCk8haZ3yjv613LVkrwOJnitNS3ugPFNf0SNML3DwoPGE-t31uIPR4TJWi5QPtaK7GJDfoUirTuSuMY3GC1BIDAr90vNxj4fjl-xxNz2fuZz28vZHcvz-6SZNd4f-5iPlnBSeo-x2dEOUHVzLbTCHcCvsRdtx-wKCO4xXsszkNtvylVdeY3l___xAprs3k90ye9VjXSuhyO7VaHX5H-eCZf86p5wbMRiXFylLV23Jt8WW1ylPkizBQrBrUeRys0mTlAlMOa40r1C7MspvIsboA6VqD1y0jxRF-WGlSpYwlhTpNl0neVrEecolv16j3NSbmlqK1gl2NJo4kMTGNitbzlDV2DgStXLe_RW5c6rpEeeCdD4ffWtsGe7BaoYvZ_I_rGZhHg">