Closed marten-seemann closed 8 months ago
Change https://go.dev/cl/561080 mentions this issue: crypto/aes: speed up AES by reducing allocation
cc @FiloSottile @rolandshoemaker @golang/security as per https://dev.golang.org/owners
I've made a similar change before in CL CL 461078, but this seems better. I will abort that change.
Go version
go version go1.21.4 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I'm the maintainer of quic-go, and I'm working on reducing the allocations during the QUIC handshake (tracking issue).
What did you see happen?
The major source of allocations lies in the standard library, especially the crypto packages. Creating AES ciphers is part of this.
The allocations coming from the two slices embedded in
aesCipher
could easily be avoided: https://github.com/golang/go/blob/b8ac61e6e64c92f23d8cf868a92a70d13e20a124/src/crypto/aes/cipher.go#L17-L21These slices have lengths between 44 and 60 bytes, depending on the AES variant (AES-128, AES-192, AES-256). By replacing them with a fixed-size 60 element array (plus one length field), the number of allocations can be reduced significantly. This also reduces pointer chasing when encrypting / decrypting data.
What did you expect to see?
I'm going to submit a CL that implements this suggestion.