It's was amazing to see how the compiler does so much optimizations behind the scenes for us. I am also interested in knowing how exactly is this black magic garbage collector sorcery done and how exactly does go optimizes this piece of code. Thanks and great video as always.
@Sachchin-710 ай бұрын
Thanks for the clear implementation! It aligns with our data flow model lessons in comp arch at uni.
@thisisamishyt Жыл бұрын
It's always a good day when Arpit posts a new video!
@westaylor4604 Жыл бұрын
You explain this so well! I am inspired to learn more! Subscribed!🎉
@asurakengan7173 Жыл бұрын
This is very obvious for people coming from C/C++ background. There's a common understanding where value types are required and where we need reference types(pointers). To add something here, there are some cases where pass by value(even though it might be slower) is the only choice - where concurrency is required. The functions implementing pass by values are untainted ones while the referential args produce incorrect results with sufficient actors running together.
@AsliEngineering Жыл бұрын
yes it is very common but how exactly that happens folks dont know about it. I tried to bridge that gap and provide an evidence. also, yes, passing values by pointer in case there are multiple threads/goroutines manipulating them can lead to incorrect result and hence it totally depends on the usecase where we might even need to pass by value even though the value is larger. totally agreed.
@shivamsinghal3972 Жыл бұрын
Hey Arpit, love the video as always! While I knew that Go optimises the pass by value and pass by reference approaches resulting in near equal times, I am curious about how exactly does Go optimise this? Do you know?
@random4573 Жыл бұрын
I never knew there was such a big performance difference between these two approaches.
@limarcospap Жыл бұрын
Thanks for the video! Nice explanation 😊
@Neb-b1w Жыл бұрын
cool video, but how the benchmark when we use compute the args, because heap is basically slower to access because it has to dereference and other concern such as when its grow the size, it has to be cool video if u make it
@RicheshGuptaRichu Жыл бұрын
Please post more on golang internals.
@salman0ansari Жыл бұрын
I'm hoping to see more golang videos from you this year.
@prashlovessamosa11 күн бұрын
thanks arpit
@sufyan2317 Жыл бұрын
Hey Arpit, I have been following your videos quite a lot and absolutely loving it. I wanted one input from you that what will be the best for me : To join system design cohort this Feb or to get enrolled in System Design for beginners. I have 7months of experience at startup and knows a decent amount of dev.
@AsliEngineering Жыл бұрын
Thank you for the kind words. If you are an absolute beginner then go for the beginners course. My masterclass is for senior engineers who have already built some systems in production.
@harshitsinghvi6158 Жыл бұрын
wow...wonderful explaination
@arpanmukherjee4625 Жыл бұрын
Great video. Its pretty annoying that languages like Java don't allow pass by value of objects and takes pass by reference as the default. Especially while writing concurrent code, we need to explicitly copy the data before passing. Even every object allocation happenning on the heap feels like being handcuffed to someone's design choices. Worth mentioning C# has structs, which are exactly like classes but passed by value, amazing feature for concurrent code using async/await.
@shardulsilswal11406 ай бұрын
Thank you for showing what happens under the hood.
@smitjainsj Жыл бұрын
One word - shaandar
@imperishableSecret Жыл бұрын
This is a cerefully crafted video to amplify the effects of this phenomenon, viewers be warned. Bluntly putting, here we are comparing the copy time for a data structure 64kb (about 8000x larger) to a pointer which is always gonna be 8 bytes (64 bits for all 64 bit processors). Practically whenever we try to access that data structure, it'll be copied to cache. Which means whenever we dereference the data structure, it'll be one more copy operation to bring that memory to cpu memory, (given we disable the compiler optimizations). So the actual difference mostly comes out to be if your function modifies the structure you're passing OR you're just using it as a parameter to carry out your computation (unless the data structure is a collection and we wanna process an individual entity). This should be the deciding factor on if you should pass by value or by reference. But keep in mind that ANYTHING THAT WILL BE PROCESSED WOULD BE COPIED TO CPU MEMORY. Learners, don't be deceived into generalising that pass by pointer is generally a better / faster approach. If a pointer is passed there's almost always a write back overhead when the modified data is rewritten back to memory to persist changes. Either this person is trying to teach without understanding the concepts himself first or he's purposely trying to decieve the learners.
@AsliEngineering Жыл бұрын
Wait before you jump the gun. I mentioned in the video that pass by pointer is good for passing "large" values across functions. But this does not mean what you should never do pass by value. PBV is great for all the reasons you mentioned and I know that really well. The motive of the video was to show how PBV and PBP are implemented because everybody knows when to use which but they don't know the real reason why.
@yash_renaissance_athlete11 ай бұрын
are you dumb or what? He literally mentioned at 13:58 to make use of PBV or PBP whenever it would make sense depending on the situation rather than blindly relying on these benchmarks. Also, even if Arpit didn’t mention that you should've the basic contextual common-sense to know that none of PBV or PBP is a silver bullet and this video just intends to showcase the benchmarks associated with JUST PASSING by value v/s reference
@reallylordofnothing6 ай бұрын
Can you share why would there be a write-back when the pointer is already pointing to the original memory location?
@pratyushsinha33483 ай бұрын
Please bring more such contents on golang🙏🙏🙏🙏
@s09021994 Жыл бұрын
The video in itself is great. Just wanted to point out the fooPBP and fooPBV tongue twisters.
@AsliEngineering Жыл бұрын
Yes I realised when I was editing 😅 will keep this in mind the next time I name a var/func.
@sandy4799 Жыл бұрын
Do same set of instructions get executed when we copy objects?
@AsliEngineering Жыл бұрын
Yes. Some changes might happen if language runtime is copying the object on heap instead of stack, but the instructions will be similar.
@nipunkhandelwal1624 Жыл бұрын
Hi Arpit Can you please tell which books you follow for golang
@AsliEngineering Жыл бұрын
Listed my books here: www.linkedin.com/posts/arpitbhayani_asliengineering-golang-redis-activity-7094169254140284928-naCB
@osamanabih1190 Жыл бұрын
What is the software you're using to display the Assembly code part?
@AsliEngineering Жыл бұрын
Drew it on Excalidraw and showed it under Obsidian.
@aviruppaul4473 Жыл бұрын
You inspire me
@tusharabbott Жыл бұрын
the real question is will the time travel function call in the future be pass-by value or pass-by reference?
@ppl_call_me_timaАй бұрын
Amazing
@xiaoshen194 Жыл бұрын
Why scheduled so late 😅
@AsliEngineering Жыл бұрын
I recorded it very late yesterday and because of work, I will not have any time to update the metadata of the video. Hence on the safe side, I scheduled it for Saturday, giving me some breathing space to update the metadata on Friday evening.
@vilasjoshi Жыл бұрын
Isn't it bcz the pass by value have to create a new variable on on stack for every call to functions? Still excited to know your explanation 🤩
@AsliEngineering Жыл бұрын
Yes. But exactly how, that is what I will be talking about in the video 😅 I am sure you will find it amusing.
@vilasjoshi Жыл бұрын
@@AsliEngineering you really do explain asli engineering behind the concepts, that's what I love most about you. Thanks for the work you share on YT. ❤️
@ankk98 Жыл бұрын
This is asli engineering
@khanra17 Жыл бұрын
Why made this simple thing super complex?
@AsliEngineering Жыл бұрын
How do you make this simpler? Can you elaborate?
@manasandmohit Жыл бұрын
The face cam video quality is a little weird. Please fix that.