golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.32k stars 17.7k forks source link

runtime: sparse zeroing in mallocgc #24928

Open josharian opened 6 years ago

josharian commented 6 years ago

This is a performance idea; it needs experimentation to see whether it is worth it.

mallocgc accepts a flag to not zero the new allocation. It is used in a few places in the runtime where we know already that we'll entirely overwrite the new memory; #24926 contemplates having the compiler use it too.

mallocgc must however always zero the new allocation if it contains pointers; runtime uses check for pointers before asking for raw memory. However, we could change the meaning of the "don't zero" flag to mean "I'm going to overwrite all the memory". mallocgc could then decide to only zero the pointers in the new memory, instead of zeroing everything. The decision to only zero pointers might be helpful if pointers are sparse in the type. Deciding whether pointers are sparse in the type is probably something we would do at compile time and set a flag in the type.

gopherbot commented 2 years ago

Change https://golang.org/cl/367496 mentions this issue: cmd/compile: add memcrlelim SSA optimization pass