Boosting the performance by being unique in Go 1.23!

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 18

  • @jub0bs
    @jub0bs 2 місяці тому +10

    Good video. Incidentally, in benchmarks written in Go 1.22+, you can replace
    for i := 0; i < b.N; i++
    by
    for range b.N

    • @FloWoelki
      @FloWoelki  2 місяці тому

      Jap you are correct, thanks for the suggestion :D

  • @vishwanathbondugula4593
    @vishwanathbondugula4593 2 місяці тому +3

    I wonder what happens when you just do one comparison without a loop, that time unique should ideally take more time because it is maintaining other things about the vars you have declared and also it might have to compute a hash of some sort on each var which might add a little more time, but I am unsure though, I will definitely give it a try. Really nice video.

  • @jamlie977
    @jamlie977 2 місяці тому +4

    you can replace `for _ = range 10` with `for range 10`

    • @FloWoelki
      @FloWoelki  2 місяці тому +1

      Fair point :D Thanks for the suggestion!

  • @SnirYehud
    @SnirYehud 2 місяці тому

    Nice video,
    I wonder what happen with more complex structs or with pointers

    • @FloWoelki
      @FloWoelki  2 місяці тому

      Thank you :) It will definitely improve the performance with more complex structs!

  • @dandogamer
    @dandogamer 2 місяці тому +1

    I noticed you write loops the same way i do which is forgetting that there is a range keyword 😂

    • @FloWoelki
      @FloWoelki  2 місяці тому

      I am kind of used to it in case I need `i` sometimes later :D but yeah, there is a neater way of writing this for loop.

  • @avinashthakur80
    @avinashthakur80 2 місяці тому

    What does second call to read memory actually show ?
    shouldn't handled be garbage collected at that point?

  • @khasanshadiyarov
    @khasanshadiyarov 2 місяці тому

    Instead of storing 1000x of "example", what handles does is that they save 1x "example" in interning way and other 999x handles are references to it, am I getting it right?

    • @FloWoelki
      @FloWoelki  2 місяці тому

      Yes, that's correct! Essentially, there is one canonical copy of "example" and 1000 handles that reference this canonical copy.

  • @cuongvu7510
    @cuongvu7510 2 місяці тому

    What is ur used font ? 🎉🎉🎉

    • @FloWoelki
      @FloWoelki  2 місяці тому

      It's the Monaspace font :)

  • @LeandroCoutinho
    @LeandroCoutinho 2 місяці тому

    You are not comparing the same thing.
    You basically create two ints and compare them, which is certainly faster.
    Move hash creation to inside the loop, them it will be a more fair comparison.
    Make hash is useful if the comparison happens multiple times.

    • @papperlapappable
      @papperlapappable 2 місяці тому

      Yes but no. It’s not comparing the same thing cause that’s the point.
      My understanding is: You’d create the „unique handle“ once at some point in advance to prepare for many expected (in this example) comparisons.

  • @adanpalma4026
    @adanpalma4026 2 місяці тому

    Umm I am trying to think in a situacion where i compare in a loop the same data. I know you do that just for explanation but we alway are compairing
    Dinamically data not static