News for hackers. Stuff that matters.
Re:Making a Go program 70% faster with a one character change by throwaway894345 on Monday November 14, 2022 @12:35PM (#33597715)
Allocating isn't "an expensive copy"; it's not analogous to clone() in Rust. The copy isn't the problem, it's the allocation.
Re:Making a Go program 70% faster with a one character change by cbsmith on Monday November 14, 2022 @12:46PM (#33597916)
I'd argue quite the reverse. Allocation can be quite efficient if done properly, but copying involves a lot of other work.
Re:Making a Go program 70% faster with a one character change by throwaway894345 on Monday November 14, 2022 @02:27PM (#33599546)
I disagree--the bottleneck here is entirely the allocation. The copying is just a memcpy and it's very fast for small structs like this; like I said, it's not the same as a clone() in Rust, which is a deep copy. If you optimized the allocation away entirely (leaving only the copy cost), there wouldn't have been a significant performance problem and this blog would never have been written.
Re:Making a Go program 70% faster with a one character change by glandium on Tuesday November 15, 2022 @05:54AM (#33607688)
Actually, you'll find that in Rust, Box::new(stuff) will too often put stuff on the stack before copying it in the newly allocated memory. For large enough stuff, that can be slower than the allocation.