Похожие чаты

Hey people, as go passes everything by value, am I

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?

10 ответов

22 просмотра

Not really, no

Ghazwan-Aliesh Автор вопроса
Liλn 🌻
Not really, no

I thought so but i can't find an argument, isn't an address memory always lighter than a copy?

Ghazwan Aliesh
I thought so but i can't find an argument, isn't a...

You shouldn’t worry about those implementation details IMHO

Ghazwan-Aliesh Автор вопроса
Liλn 🌻
You shouldn’t worry about those implementation det...

u mean the performance benefit isn't that big to justify this? or there is possible no performance benefit at all?

Ghazwan Aliesh
u mean the performance benefit isn't that big to j...

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

Ghazwan Aliesh
I thought so but i can't find an argument, isn't a...

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

Ghazwan Aliesh
I thought so but i can't find an argument, isn't a...

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.

Ghazwan-Aliesh Автор вопроса
Roman Sharkov
it really depends. Yes, sometimes passing a big s...

👍 I totally missed that it's garbage collected.

Похожие вопросы

Обсуждают сегодня

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
Привет)) уже кажется эту тему перемусолили, но вот я так и не понял. Я сейчас сижу на 27дюймов 2к мониторе. На Актуальной макоси, если я куплю 27д 4к монитор: - будет ли изобр...
Vladislav Piskunov
15
Hi guys, any problem with Pulsebrige? Trying to transfer from wETH to ETH. First it tells me to connect my metamask "through mobile app" not desktop. Then I did and confirmed ...
Snowflakecrypto
13
any reference of this implementation?
BitBuddha
29
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
&"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\dumpbin.exe" /EXPORTS C:\Users\Yeet\Tauon\vcpkg\installed\x64-window...
Martin Rys
6
Карта сайта