guaranteed to get always a better performance by passing complex types (slices, maps, arrays .. etc) by reference and returning a reference to the result to de-reference it in the function consumer? is it that simple?
Not really, no
I thought so but i can't find an argument, isn't an address memory always lighter than a copy?
You shouldn’t worry about those implementation details IMHO
u mean the performance benefit isn't that big to justify this? or there is possible no performance benefit at all?
Again, it depends. I don’t think there’s a particular performance benefit. I think you should think about code in terms of readability and not speed
There is a garbage collector in go. Therefore not always faster
what do you mean by "by reference?" there's nothing like that in Go
it really depends. Yes, sometimes passing a big struct that's more than 64 bytes in memory can be more expensive than passing a pointer which is pointing to it. BUT you have to remember that Go is a garbage-collected language. If it's allocated on the heap due to escape enalysis it will create garbage that the GC will ultimately have to clean up, which increases overall system load slightly (this can add up if you do it too often) However, on most architectures copying structs smaller than 64 bytes is near instant (best way to check is to write a benchmark) so using a pointer can result in worse performance.
👍 I totally missed that it's garbage collected.
Обсуждают сегодня