Похожие чаты

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 ответов

26 просмотров

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.

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта