Understanding Allocations: the Stack and the Heap - GopherCon SG 2019

  Рет қаралды 67,860

Singapore Gophers

Singapore Gophers

Күн бұрын

Speaker: Jacob Walker, Ardan Labs (@jcbwlkr)
Like C, Go uses both stack and heap memory. How can a Gopher know which is being used? Can you influence this decision? What effect does it have on your program? Are there any tools to help? This talk answers those questions and more.
About the speaker
Jacob is a software developer, community organizer, and has really nice hair. Like ridiculously nice hair.
He started his career creating web applications in PHP, Ruby, and Node.js. When he discovered Go he dove in deep and hasn’t regretted it for a minute. He is now a Community Engineer with Ardan Labs where he is focused on helping members of the Go community.
Event Page: 2019.gophercon.sg

Пікірлер: 55
@HSharpknifeedge
@HSharpknifeedge 3 жыл бұрын
So far, this is the best explanation of Escape Analysis, comparing with many others, which are right now on the right side of the screen, suggesting by KZbin. Awesome, thanks again!
@jaredcastro8862
@jaredcastro8862 2 жыл бұрын
I also agree. Clean and short
@ugur_dincer
@ugur_dincer 4 жыл бұрын
Clear and smooth, also io.Reader part was nice
@nyashachiroro2531
@nyashachiroro2531 Жыл бұрын
It was super nice. Literally an aha moment for me. This was a great talk.
@TehKarmalizer
@TehKarmalizer 9 ай бұрын
It made me think of similar functions in other garbage collected languages differently as well.
@Pherecydes
@Pherecydes 8 ай бұрын
I hadn't understood why the io.Reader interface works the way it does... now I get it, thank you! Excellent talk.
@wentaoqiu4072
@wentaoqiu4072 3 жыл бұрын
Simply amazing, points are clear and explained throughly, thanks so much.
@anaray567
@anaray567 Жыл бұрын
This clear why io.Reader is designed the way it is ! Very clear and precise presentation ! Thanks
@thepolyglotprogrammer
@thepolyglotprogrammer 3 жыл бұрын
Really good example about the io.Reader.
@Wielorybkek
@Wielorybkek 8 ай бұрын
That was super interesting, I've learnt a new thing!
@nicksypteras8594
@nicksypteras8594 2 жыл бұрын
That io.Reader example at the end was great!
@ideaparkcc
@ideaparkcc 9 ай бұрын
It can be concluded that: system api should not be responsible for resources management (most of times it refers to memory), but only for logical evaluation.
@kamilziemian995
@kamilziemian995 3 жыл бұрын
21:20 Great ending point to great presentation.
@jub0bs
@jub0bs Жыл бұрын
Excellent talk!
@alex6161
@alex6161 Жыл бұрын
The best explanation, thank you Jacob !
@luqmansen
@luqmansen 4 жыл бұрын
Great explanation!
@KurtisRader
@KurtisRader 4 жыл бұрын
The question at the end of the talk is interesting. I would have provided a slightly different answer. The primary way to address performance concerns is by picking the appropriate data structures and algorithms. It is almost always a mistake to focus on minutiae; i.e., usually insignificant implementation details.
@baxiry.
@baxiry. 3 жыл бұрын
usefull
@АлександрКостюченко-у4х
@АлександрКостюченко-у4х 2 жыл бұрын
He is really good. Thank you!
@rogeriof2315
@rogeriof2315 2 жыл бұрын
Really nice explanation!!!
@CLE2022
@CLE2022 Жыл бұрын
This is really good
@vamsikrishnasiddu3525
@vamsikrishnasiddu3525 3 жыл бұрын
Amazing explanation
@speedTurtle
@speedTurtle Жыл бұрын
Cogent. I learned something here.
@mzcustom2
@mzcustom2 Жыл бұрын
I think the point he made at 14:00 could be somewhat misleading as he's emphasizing "moved to the heap right at compile time". The escaped variables still have to be dynamically allocated in heap, so it's complied to call runtime.newobject which calls mallocgc, therefore there's no cost benefit at runtime. Also, I believe this speaker isn't experienced in C programming, not that I'm faulting it, judging by the fact he initially didn't understand why the read function of io.Reader uses a byte slice as its argument instead of an int. That's exactly how read in C works where the caller sends a buf pointer (along with the buf size or less) and gets the number of bytes filled in as the return value, just like all the other functions do unless the argument is a small struct that fits in the registers or a primitive type. From what's known, Golang is a brainchild smart men from Bell Lab who hated C++, so it quite closely follows Unix/C programming style.
@edb75001
@edb75001 3 жыл бұрын
Very informative... much appreciated.
@xiaodonghuan2285
@xiaodonghuan2285 4 жыл бұрын
Thanks for your reply. nice post!!!
@GertCuykens
@GertCuykens 5 жыл бұрын
Can I assume that most return err values in common golang programs end on the heap? Or does err get special treatment?
@foolishway4257
@foolishway4257 3 жыл бұрын
Good question.
@marianzagoruiko
@marianzagoruiko 3 жыл бұрын
I don't think it does. Allocation only happens if you return a pointer to the variable. In case of error, the value is being returned and not a pointer.
@swibay
@swibay 2 жыл бұрын
​@@marianzagoruiko You're right!
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 2 жыл бұрын
wow, I came looking for copper and found gold
@kevingeorge3983
@kevingeorge3983 5 жыл бұрын
awesome
@johnedissonrodriguezcucanc9131
@johnedissonrodriguezcucanc9131 Жыл бұрын
Amazing explanation, I just have any doubt, what is the difference between "&x scapes to heap" and "moved to heap". Thks
@shubhamdhapola5447
@shubhamdhapola5447 Жыл бұрын
It's just the matter of how much of the program behaviour the compiler is able to acknowledge. At compile time, the value a variable holds "escapes" to (allocated on) the heap, if the compiler is confident and almost-omniscient of the program's semantics and control flow in the vicinity of variable declaration and usage (like Go, unlike Python). Else if compiler only has partial information, it will allocate an empty memory slot for the variable ahead-of-time and runtime behaviour will unveil that it needs to be "moved" to the heap.
@slabchan7310
@slabchan7310 3 жыл бұрын
Thanks for sharing
@Mimookrokodill
@Mimookrokodill 4 ай бұрын
Awesome
@kanybekmomukeev4116
@kanybekmomukeev4116 Жыл бұрын
Best of best
@AnonAristotel
@AnonAristotel 2 жыл бұрын
Awesome.
@EdwardWork-m5t
@EdwardWork-m5t 11 ай бұрын
Thank you beer belly Jesus
@DagangWei
@DagangWei 5 жыл бұрын
17:30 wondering why in the right hand case, it is not `read(&b)` and `func read(b *[]byte)`? in other words, why it doesn't need pointer? (I am new to Golang)
@JacobWalker0814
@JacobWalker0814 5 жыл бұрын
The structure of a slice contains a pointer to a backing array of elements. You almost never take the address of the slice itself since it behaves like a pointer already.
@DineshGowda24
@DineshGowda24 4 жыл бұрын
Slice will already have a pointer to an array. When you pass a slice to the function, even though the slice will be copied only the underlying address of array will be copied. So any changes on slice will affect the underlying array. So need to pass potiner to slice. Also a slice would look like struct slice{ ptr *[cap]Type, cap int, len int}
@TehKarmalizer
@TehKarmalizer 9 ай бұрын
@@DineshGowda24 it really depends on what you are doing with the slice. If there may be side effects that reallocate the underlying array (and therefore the slice), that reallocation will be local inside the function, and the original slice and array will be unaware of the side effects. Maybe that is desirable, but maybe it is not.
@marianbuciu7853
@marianbuciu7853 Жыл бұрын
can someone explain 17:55?
@androth1502
@androth1502 5 жыл бұрын
so why can't we just put stuff on the bss segment?
@elio8119
@elio8119 4 жыл бұрын
Because Go was created to be simple and not support this kind of intrinsics.
@gngn2973
@gngn2973 3 жыл бұрын
If i understand correctly, for "correctness", you want to try your best to stay off of the heap whenever possible? Great video really cleared some things up for me, being a fairly new programmer.
@TehKarmalizer
@TehKarmalizer 9 ай бұрын
No, for correctness, you want the program to perform the intended behavior. And you want it to keep doing so when anyone needs to change the code.
@gngn2973
@gngn2973 9 ай бұрын
@@TehKarmalizer yea I've come a long way since that comment lol. Thank you for the response tho =)
@mridulrathod3681
@mridulrathod3681 3 жыл бұрын
superlike
@yapayzeka
@yapayzeka 3 жыл бұрын
who put the like at 1:05 :D
@user-ge8fn4jr5q
@user-ge8fn4jr5q 4 жыл бұрын
wtf is go anyway...
@Jonasmelonas
@Jonasmelonas 4 жыл бұрын
ok boomer
@TheMrKeksLp
@TheMrKeksLp 4 жыл бұрын
ok zoomer
@Aditya-ne4lk
@Aditya-ne4lk 3 жыл бұрын
fumt
Garbage Collection Semantics - GopherCon SG 2019
26:56
Singapore Gophers
Рет қаралды 16 М.
规则,在门里生存,出来~死亡
00:33
落魄的王子
Рет қаралды 32 МЛН
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 289 М.
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 136 МЛН
Как на самом деле устроены каналы в Golang? | Golang channels internals
41:31
WHY IS THE HEAP SO SLOW?
17:53
Core Dumped
Рет қаралды 244 М.
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
Управление памятью и сборщиком мусора в Go
47:26
Московский клуб программистов
Рет қаралды 12 М.
Concurrency is not Parallelism by Rob Pike
31:22
gnbitcom
Рет қаралды 134 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 819 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 113 М.
Как на самом деле устроен тип Map в Golang? | Golang под капотом
34:33
规则,在门里生存,出来~死亡
00:33
落魄的王子
Рет қаралды 32 МЛН