crypto/aes: AES cipher creation and encrypt / decrypt operations can be sped up significantly #65507
Labels
FixPending
Issues that have a fix which has not yet been reviewed or submitted.
FrozenDueToAge
Performance
Milestone
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:go/src/crypto/aes/cipher.go
Lines 17 to 21 in b8ac61e
These 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.
The text was updated successfully, but these errors were encountered: