hash/crc32: data leaks to heap #58781
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I haven't tried the latest release but from what I see there's not much change to affected code so far.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wrote a simple benchmark to showcase the problem.
https://go.dev/play/p/H_cHsnLhMiW
Or you can see
runtime.MemStats
with growing fieldTotalAlloc
here:https://go.dev/play/p/8geJhJ6OOqS
What did you expect to see?
The
data
variable in the benchmark should be allocated on the stack becauseUpdate
does not retain the slice. Hence no allocations should be made per operation.What did you see instead?
We have an allocation due to
data
escaping to heap. I believe the reason is thatupdateCastagnoli
which does the calculation is declared as the closure and it is initialized during runtime depending on CPU capabilities (SSE4.2 etc).Maybe we could rework initialization of crc32 algorithm without additional level of indirection. I relocated some of Go assembly code for SSE4.2 to my private project and it shows no allocation and a significant performance boost (by a factor of 3 or 4 on some data).
The text was updated successfully, but these errors were encountered: