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

Поделиться
HTML-код
  • Опубликовано: 27 дек 2024

Комментарии • 55

  • @HSharpknifeedge
    @HSharpknifeedge 3 года назад +56

    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 RUclips. Awesome, thanks again!

  • @ugur_dincer
    @ugur_dincer 4 года назад +34

    Clear and smooth, also io.Reader part was nice

    • @nyashachiroro2531
      @nyashachiroro2531 Год назад +1

      It was super nice. Literally an aha moment for me. This was a great talk.

    • @TehKarmalizer
      @TehKarmalizer 11 месяцев назад

      It made me think of similar functions in other garbage collected languages differently as well.

  • @Pherecydes
    @Pherecydes 10 месяцев назад

    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 года назад +11

    Simply amazing, points are clear and explained throughly, thanks so much.

  • @kamilziemian995
    @kamilziemian995 3 года назад +2

    21:20 Great ending point to great presentation.

  • @anaray567
    @anaray567 Год назад

    This clear why io.Reader is designed the way it is ! Very clear and precise presentation ! Thanks

  • @thepolyglotprogrammer
    @thepolyglotprogrammer 3 года назад +1

    Really good example about the io.Reader.

  • @nicksypteras8594
    @nicksypteras8594 2 года назад

    That io.Reader example at the end was great!

    • @ideaparkcc
      @ideaparkcc 11 месяцев назад

      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.

  • @GertCuykens
    @GertCuykens 5 лет назад +10

    Can I assume that most return err values in common golang programs end on the heap? Or does err get special treatment?

    • @foolishway4257
      @foolishway4257 4 года назад +1

      Good question.

    • @marianzagoruiko
      @marianzagoruiko 3 года назад +6

      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!

  • @Wielorybkek
    @Wielorybkek 10 месяцев назад

    That was super interesting, I've learnt a new thing!

  • @jub0bs
    @jub0bs Год назад +1

    Excellent talk!

  • @marianbuciu7853
    @marianbuciu7853 Год назад

    can someone explain 17:55?

  • @alex6161
    @alex6161 Год назад

    The best explanation, thank you Jacob !

  • @KurtisRader
    @KurtisRader 4 года назад +2

    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.

  • @mzcustom2
    @mzcustom2 Год назад +1

    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.

  • @DagangWei
    @DagangWei 5 лет назад +4

    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 лет назад +7

      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 года назад +3

      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 11 месяцев назад

      @@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.

  • @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.

  • @luqmansen
    @luqmansen 4 года назад +3

    Great explanation!

  • @vamsikrishnasiddu3525
    @vamsikrishnasiddu3525 3 года назад

    Amazing explanation

  • @rogeriof2315
    @rogeriof2315 2 года назад

    Really nice explanation!!!

  • @АлександрКостюченко-у4х

    He is really good. Thank you!

  • @speedTurtle
    @speedTurtle Год назад

    Cogent. I learned something here.

  • @xiaodonghuan2285
    @xiaodonghuan2285 4 года назад

    Thanks for your reply. nice post!!!

  • @CLE2022
    @CLE2022 2 года назад

    This is really good

  • @kevingeorge3983
    @kevingeorge3983 5 лет назад +3

    awesome

  • @a_maxed_out_handle_of_30_chars
    @a_maxed_out_handle_of_30_chars 2 года назад +2

    wow, I came looking for copper and found gold

  • @slabchan7310
    @slabchan7310 3 года назад

    Thanks for sharing

  • @edb75001
    @edb75001 3 года назад

    Very informative... much appreciated.

  • @androth1502
    @androth1502 5 лет назад +1

    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.

  • @Mimookrokodill
    @Mimookrokodill 7 месяцев назад

    Awesome

  • @AnonAristotel
    @AnonAristotel 3 года назад

    Awesome.

  • @kanybekmomukeev4116
    @kanybekmomukeev4116 2 года назад

    Best of best

  • @EdwardWork-m5t
    @EdwardWork-m5t Год назад

    Thank you beer belly Jesus

  • @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 11 месяцев назад +2

      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 11 месяцев назад

      @@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 года назад +1

    who put the like at 1:05 :D

  • @user-ge8fn4jr5q
    @user-ge8fn4jr5q 5 лет назад +3

    wtf is go anyway...

  • @Aditya-ne4lk
    @Aditya-ne4lk 4 года назад

    fumt