Navigate Select ESC Close

Optimizing Loops In Go | Prime Reacts

2024-02-17 Science & Technology
85.8k
2.6k
183
ThePrimeTime
ThePrimeTime
1.1m subscribers

Unlock all features

FREE: Get instant access to 10 AI summaries, chats, or transcripts per day.

Description

Recorded live on twitch, GET IN https://twitch.tv/ThePrimeagen Become a backend engineer. Its my favorite site https://boot.dev/?promo=PRIMEYT This is also the best way to support me is to support yourself becoming a better backend engineer. Reviewed video: https://www.youtube.com/watch?v=lYn9PPeQBFU By: https://www.youtube.com/@softwarechats9307 MY MAIN YT CHANNEL: Has well edited engineering videos https://youtube.com/ThePrimeagen Discord https://discord.gg/ThePrimeagen Have something for me to read or react to?: https://www.reddit.com/r/ThePrimeagenReact/ Kinesis Advantage 360: https://bit.ly/Prime-Kinesis Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other)) https://turso.tech/deeznuts

Top Comments (10)

@DjoumyDjoums 2024-02-17

My guess on why 3 is slower than 2 : index bound checks. Compilers can very often eliminate them when you loop on the actual length of the array, not a pre-cached numerical value.

120 14 replies
@abdia-lb2yx 2024-02-17

I ain't gonna lie having an influencer style videos in the coding world just entertainment non educational helps me stay on track when i feel not motivated to study keep it up bro.

115 3 replies
@HairyPixels 2024-02-17

The compiler writes better code than you but what if you're writing a compiler? BRAIN MELTING

39 8 replies
@andygarfield6529 2024-02-17

There’s all sorts of things he could have done here. Changing the order of the loops can give you wild improvements because it can change the proportion of cache hits. Also loop unrolling. Also using arrays in Go (which are a real thing) instead of slices.

24 5 replies
@ColinFox 2024-02-17

Go uses symbol lifetimes to determine whether to allocate on the stack or on the heap. If the object survives after the function returns, it's on the heap. Pretty straightforward.

18
@susiebaka3388 2024-02-17

"The more you write standard code, the more likely you're generally doing well." - ThePrimeagen

17
@samsqu4red 2024-02-17

Found the channel just few weeks ago. Coming from a background in Webflow, with only a grasp of HTML, CSS, and a bit of JavaScript, I see myself as a puppy. Recently, I've decided to take coding more seriously because it's interesting, and I also have a web app idea that I'm genuinely determined to bring to life. Though 90% of what the man is saying still flies right over my head, I feel like my understanding is expanding. I've never attended school, worked in-house with a team, or studied with guidance. It seems like I found a semblance of a mentor who's bombarding me with jargon I can't possibly comprehend, but ultimately is helping me see throw the fog in a way. Feels like little by little I'm starting to grasp how everything is connected.. weird.

13
@jagc2206 2024-02-17

There is a big distinctions between array an slices in go. This video uses slices, which are pointers to arrays. A slatic array will have a compile time length and allows the compiler to do a lot more optimization

10 1 replies
@rt1517 2024-02-18

The video author should have disassembled the resulting binary to see if he would be able to figure out what the hell is going on.

3
@g.c955 2024-02-18

he could to a follow up by profiling the code to see where CPU and memory are spent, then analyze the assembly output of the code to understand why.

2

Unlock the Data Inside
Turn Videos into Knowledge

  • Get FREE 10/day: transcripts, summaries, chats
  • Chat with videos, export text & PDF
  • $1 free API credit for RAG, chatbots & research

Free forever plan • All features unlocked

App screenshot