3 ms·
> But, just like in Java, if I need speed, I can preallocate and reuse memory to avoid hitting the GC. No, you can't. Language constructs in Go allocate in way
by pcwalton 7y ago
> But, just like in Java, if I need speed, I can preallocate and reuse memory to avoid hitting the GC.
No, you can't. Language constructs in Go allocate in ways that are not immediately obvious. When the GC runs, it still has to scan all of that memory, regardless of whether you preallocated it or not, which is especially unfortunate with a non-generational garbage collector like that of Go.
Also, I have to say that I really don't get it when people say that they have to think about the borrow checker for a long time before writing a program in Rust. That's not the case for me or anyone else I know.
- skybrian 7y agoOne possibly useful thing to know is that the Go GC doesn't scan non-pointer memory, so if you have big strings, byte arrays, or structs that don't contain pointers, they don't need to be scanned. Also, while the garbage collector may not be generational, it's mostly concurrent. Looks like GC pauses are below 1ms now?