tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
14.72k stars 858 forks source link

gc_leaking: Don't zero out new allocations on Wasm targets #4302

Open lpereira opened 1 week ago

lpereira commented 1 week ago

Wasm linear memory is always initialized to zero by definition, so there's no need to waste time zeroing out this allocation.

aykevl commented 1 week ago

For -gc=leaking this seems correct. But in fact, you can do this optimization for every system except for baremetal (and nintendoswitch I think). Linux and Windows zero the memory in mmap and VirtualAlloc. For MacOS I couldn't find it anywhere online, but I would be very surprised if the returned pages weren't zeroed: every other Unix variant does this.

dgryski commented 6 days ago

@aykevl So I guess we can just tweak the build tags here. LGTM otherwise.