How to make TypeScript Blazingly Fast (JavaScript/NodeJS)
Вставка
- Опубліковано 26 вер 2024
- I have been doing some performance stuff at Netflix for some time. I wanted to take some time to share with you two very specific techniques for making your applications faster.
One of the two steps is surprisingly beneficial.
HERE IS HOW TO RUN THE PERF COMMANDS:
GO TO THIS LINK: github.com/The...
Links
Linode: linode.com/prime
Discord: / discord
Twitch: / theprimeagen
Insta: / theprimeagen
Twitter: / theprimeagen
VimRC & i3: github.com/The...
Keyboard (15% off, I don't earn commission): bit.ly/primeag...
#vim #nodejs #javascript
I hope you liked this video (literally, press the damn button already). If you like comparison videos / perf videos LET ME KNOW. TELL ME AND I'LL KEEP MAKING THINGS!!! Else I'll quit and make a vlog about my new protein drink line. ITS NOT A PYRAMID SCHEME... its a triangle.
Yes keep going
Love that contenttt , please do rust
I like it
Oh shit I forgot to add pooling to the database connection in my hobby project!
Performance videos are the best!
This is becoming one of my favourite programming UA-cam channels... Blazingly fast!
Most excellent!
@@ThePrimeagen I think you're my favourite programming channel now too. Only downside is you make me feel like dogshit when you roll out optimisation like this beast! 😁
I really liked the graphs being included. Also i learned about flame graphs!
Yeah. FlameGraphs are SUPER useful.
Agreed, I’ll for sure be using flame graphs in the future
Amazingly good combo of tempo, humour and insightful knowledge. Been professionally developing for about 15 years. Loved this video big time!
Awesome! My goal is to make non slow tech videos :)
@@ThePrimeagen that feels like an untapped market on UA-cam. Excited to see you pushing more of these out over time!
@@ThePrimeagen You could say your tech videos are... BLAZINGLY FAST
Oh Sheets, this guy is a data wizard
🧙♂
Prime is coming to steal jobs from data scientists LUL
@@adgai prime?
just strted a bootcamp 3months ago and had some prev exp so i can understand maybe 15% of your content but nonetheless im learning a new little fragment of concept in every video that hopefully i will be able to master later..your energy is an inspiration...lets all screaaam moreeeee goddaaaaamn
YAYAYAYAYAYA! Keep your chin up, you got this babe!
Dude, that was a BLAZINGLY good video.
I love how you add some humor to this technical content.
By the way, the content was excellent by itself. It's good to know the tools you use to analyze the performance and how you optimized the code!
This blew my mind. Time to start monitoring the performance of my node server
awesome! I thought the memory stuff was really surprising for me.
clicked the vid blazingly fast
And like the vid blazingly fast
Karen!!
watched the vid blazingly fast at 2x the speed of normie watchers who watch at 1x!!!!
Can’t wait for the Rust vs go comparison
same! Almost done with the go server.
The Primeagen: Bringing the science back to computer science since 1969
ua-cam.com/video/cbCu9sUzcXg/v-deo.html
I’m in love with this channel, it’s amazing. Wish there were even more videos.
Trying! Its hard to make good videos :)
There's more science in this video than 90% of the academic papers that I had to read in my academic career, congrats man :)
Awesome content as always.
There is a lot to learn from the way you approach optimization (I mean who doesn't want a bigger blue bar?), as without numbers you are just blind in the mist.
Flame graphs are awesome!
yayaya! Always start with a proper yard stick.
I just can’t believe how you manage this! Eng gig at Netflix, an ever increasing family size, what, is it now, 5 or 6 kids(?), live streams on twitch and then these buttery smooth, MCT oil’y goodness on the UA-cams! Keep up the great work!
It's the mcts baebee
@@ThePrimeagen hmmmm....it's always the MCTs!!!!
I like the eloquence of your videos, I appreciate you, you give me inspiration to make better code Blazingly fast!
BLAZINGLY FAST!
Thank you for the nice words.
It has become rare, that YT videos really make me lol, but man, you definitely still got the power to make me giggle. Top notch blazingly fast sub!
Great video man. I really enjoy your content and always wait for a new video. Optimisations and comparisons are always interesting to watch. Keep up the good work.
awesome! Hopefully you feel like you had a couple of action items to take away if you ever work in node.
The great thing about your videos is that the things you show can be applied anywhere with any language which is awesome.
Also because you are ThePrimeagen I have to mention… I started using Neovim because of you. I wish I get as comfortable as you are someday.
I love optimization videos and it's really cool to see your process and tools to solve a slow implementation problem. Keep them videos coming!
Big ups for sharing/exposing us viewers to this visualization tool for identifying performance bottlenecks….so clutch!
Thumbs up 👍
I sadly missed this stream, caught the tail end of it as you were building the graphs. This content is amazingly blazingly fastacular. I got a little randy when you described the use case for the memory pool and then saw the improvements with it… best programming content on the web for people who actually have to build stuff.
Hah! Now it's a bit dangerous doing pools. They are hard to use properly
@@ThePrimeagen But what if it's a pool of coconut oil?
Love the content! Your DSA course on Frontend Masters is one of the best contents I have ever watched. It really lives up to the expectation. Nothing has got me nearly excited about DSA as much as that course. Thank you very much. Love from Ghana! :)
Love the video! The mix of informative and funny is well balanced and I learned something out of it.
awesome! Did memory part surprise you?
Wow! Not gonna lie the memory pool stuff felt over my head a bit but hey, this is good stuff Prime. More comparison/perf stuff plz.
JSJOEIO!!! What??!!! Memory pools are the bestest!
@@ThePrimeagen lol guess i've never had a reason to use em'??? but with those performance gains, might be worth learning
need this TYRONE content streamed directly into my brain
get ws, a blazingly fast library.
Rewatching this after SOLIDjs dev hour is even more satisfying. Thanks for reminding
LOVE THIS! Awesome video, I loved how you went over the ring buffer, always nice to see some cs theory in the mix
This is such a great video! Got introduced to this channel at work!
great! I am happy you like this.
Would love to see similar benchmarks and profiling in Go 🙏
I am going to try to do some great go content.
That is next. Next will be a rust vs go.
This was refreshing, the information been shared in this channel is on point!
Yayayayaya! Ty. Just trying to cut through the yt bs
I LOVE seeing these perf videos, just subbed :D
Keep them coming!
Great video. Loved how you told the story of the whole optimization process illustrated with your graphs. Showing us how to apply these tools along the way. And getting great results by applying some good fundamentals in algorithms and memory management.
While I do like the overall tempo of the video, I find that getting too many shortly spaced cuts in your speech when you're explaining something more complicated can be a bit jarring and interfere with fully comprehending the content.
Solid feedback. I'll consider that moving forward.
@@ThePrimeagen I think this is a personal preference. I like the cuts, makes it more compact and keep my attention.
Great content! Somehow I really like JS things, and these kind of content is awesome. This is becoming my fav tech channel
had seen this video around 6 month's before, did'nt understand shit. It was recommended again in my feed today, and i tottally understand everytying. feel's so damn good!
Does the primagen edit his own videos? Cause the editing is sharp and hilarious
I’m the editor:) Thank you I appreciate that!
@@flipmedia1597 Right on! The editing is hilarious! Great stuff 🙏
@@flipmedia1597 The editing is next level. It's as tight as hand-written assembler code.
Unbeatable content, congrats!
How long did it take you to get this done? How did you measure the avg health of your loops and generated those charts?
To make the example took ~30-40 hours of programming
To collect that data took about 10 hours of different experiments
To measure the health: github.com/ThePrimeagen/tyrone-biggums/blob/master/typescript/src/game_loop/game-callback.ts#L22
That collects the stats then whoever is the winner of the stats will send down how many currently active games were being played + the 8 points of data representing the count in each bin. Used a simple script to post process all the data transfered.
thanks for covering the flame graph stuff. that was really interesting to learn about
I would like to invite Prime to make a lecture for my students... problem - we use VSC 😬😅❤🤗 still - I love Primeagen 🎅
hahah! that is ok. Students have to start somewhere.
Vscode is the only way, vim is for pure savages
I liked that I got to know how to improve performance of typescript programs. I would also like to know about a complete suite of tools, where database calls from typescript can also be viewed on a graph.
Yeah, more is awesome. A lot of these tools you speak of are pay to play
12 minutes? That is not blazingly fast at all
Just finished the video, and it was really interesting! Great job
I do love you, don't mind my twitter presence... he is a jerk.
really like the case study, really easy to follow. I would really like to see some C++ experiment from you, maybe in comparison with Rust?
I'll be doing go vs rust. c++ is just soooooo much effort. I'll spend like 15 hours just getting the proper build system
@@ThePrimeagen Yeah, I completely understand the problem with C++ for these "side-experiments". Go vs Rust sounds awesome!
Great video prime! Keep it up, love the graphs
good. I do too :)
Entertaining, fun and full of new techniques to learn! *_BLAZINGLY FAST_* channel!!!!
man that was really informative video
♥♥♥
you are welcome :)
Boy oh boi! that was Blazingly FAST!
🏃♂️⚡️⚡️
thank you marcos :) See you on twitch.
Love seeing those graphs 😍😍😍
Absolutely loved this video. Thank you.
You are welcome
never seen flamegraphs but they seem to be a nice thing! thanks for showing those to us
I liked this video very much and I learned a lot. Keep up the good work! ❤💪
Thank you
This is great content!
Currently my code is mostly slowed down by the slow rendering engine, so I was on a mission to simplify the HTML. Removing layers of containers (DIVs), replacing some with simple padding/margin.
Probably going to look at object creation next.
Such an interesting video, love the heavy use of data to prove your changes actually made a difference. Would love to see this kind of stuff compared with Rust and it’s non-garbage collected memory management.
Amazing content as always! I would like to see this comparisons vs unoptimized Go server
yeah. That is literally next.
I would be interested in more in-depth js optimization videos, nice job!
woo just learnt about flame graphs, really cool!
Super insightful. Heading on to twitch now. Also, I hope this comment helps you plot those sweet perf improvement graphs.
Ty, and they do
I would really like to see some more in-detail optimization tutorials about tools and how to use them for JavaScript/TypeScript. 😊
Ahyo, just discovered this channel and I'm VERY interested in this optimization stuff, specifically for TS, but also with regards to the "how do you actually measure stuff". Explaining perf some more would be amazing. I cant really join twitch because of timezones, but if some of that made it to your yt-channel, I would be very happy!
Good job!
I personally would like to see a similar comparison with Go.
its already on its way.
looking forward to the RxJS part
we will see :)
This is now my fav programming channel
Also everything for some reason became blazingly fast
Even my anxiety
Help
this happens to us all
It would be great to delve deeper into flame graphs 🔥
!!! You never know! I want to play around with the go performance tooling.
@@ThePrimeagen i would highly recommend that if you have some time to spare!!
GIVE RUST AND GO GRAPHS!! Also would love you join your protein drink line triangle.
Excellent! You will get paid based on how much you sell and how many more triangles you can get under you.
me likes it, me likes it a lot. Please do a Go and Rust comparisons!!! Now putting myself into await pool for that
yayayayayayaya! Just don't forget to bring your Tokio Mutex if you are awaiting into the pool.
Awesome!!!!, I really enjoy watching this!!!!!
Just a comment to increase the comment amount graph. Your content is golden!
Ya ya, ty
I saw those flame graphs when profiling my app, but didnt really know how to read em 😂 Happy i do now
This is gold content. I love it!
I Usually do not comment, but I wanted to help you satisfy your graphs fetish.
ty ty ty! Its very fetishy too
I am amazed. Incredible content!
you are welcome!
I am glad you liked it.
Just letting you know: I like this content
THank you :)
I WANT MORE OF THE PRIMEAGEN!!!!!
I AM TRYING
this is awesome! I hope to quit writing CSS and start writing flame graphs one day.
One day, in the not so distant future?
We LOVE tthese blazingly fast videos ♥️
Awesome. I hope you enjoyed this.
I’m really glad to see you comparing TS with Rust and Go. And in such a digestible format. Quick, understandable, and funny!
I feel like the Rust and Go discussions ignore the fact that the majority of the job market for web is using JS/TS. And JS/TS developers ignore the hit to performance and server costs. Rust is incredible until you actually try to build something real. Go seems nice but falls short in it’s promise for simplicity, and has made some strange decisions.
Great video!
I find go to be great. It gets better and better as you understand some of its decisions. I am fine with almost all of it
Rust on the other hand. It is hard, but I am getting faster working through a lot of rusts weirdnesses as well. Each I can appreciate.
At this point I am unsure if I am faster at JS or Rust for a lot of things.
Wanting this series to keep going…
Just got done collecting the date for part 3!!!
@@ThePrimeagen
Cool video dude. Yeah, JavaScript performance is strongly coupled to explicit memory management. As a general rule, avoid 'new' in hot code paths (allocate as much memory as you can up front and reuse). JavaScript
also suffers from not being able to allocate structures on the stack (so all objects go on the heap + implicates the GC), in some extreme optimization cases, it may be nessasary to inline object properties to flat primitive values that do sit on the stack. There's an art form to making JS go fast, pity about the shit Web Socket libraries available for Node. You should performance benchmark Deno native Web Sockets vs Nodes ws library.
How about bun? Where could I read about keeping js stack leaner? Thanks for the tips you gave.
@@ebrelus7687 At this stage, the only way to keep JS lean is by writing code yourself and avoiding NPM dependencies (and then refining your code over years). Basically, you want to be writing directly against the core modules provided by the platform only (and only take dependencies if you absolutely have to)
As for Bun, best to wait. However I'm skeptical that Bun will see significant performance increases over Node/Deno in practical use cases. The only thing Bun is doing that the other platforms are not (afaik) is implementing the sendfile API (which allows it to do zero copy of buffers and avoids kernel space to user space copies). Systems like Kafka use this API for performance, but it's fairly niche in terms of the places it can be applied.
Id stick with Node/Deno for the foreseeable future.
Wow!! That's blazing fast 😮
Such Fast
Much wow
The guy who screams in the video is literally my definition of pro. Wanna be like that guy one day.
I do like screaming
That red line at 11:09 was smoother than my linear Thocky Switches ❤
kreygasm!
Reusing bullets... Sounds even more violent.
Such violence, much wow.
Loved it.
Awesome! I am happy here :)
This is amazing stuff I can watch this all day
Multi-threaded JS, native add ons, data driven eng initiatives. These 👌
This video does not make any sense to me, but I like it and I will watch it again.
Why not? Are you new or am I bad at explaining?
@@ThePrimeagen Wathed the video again, Awesome. Thanks for introducing flame graph, node --inspect and how to use pool and ring buffer. And you got it, I'm pretty new :)
This is great 😍
Awesome. Thank you grim
This is cool!
I agree!
1st watch: wait what
2nd watch: oh, so the game is this loop, and it advances time, and bullets kill bc of fire rates, and increased load makes the loop fluke (wait how did he measure load)
3rd watch: wtf is a "linode instance". Ok so you do a flamegraph of the backend, Identify which ring is actually your code and figure out how to optimize. And you can do the same to measure memory consumption in chrome debugger and optimize in that regard, up to the point of barely gross.
yeah amazing video, really loved learning about this technique
I want, in a degenerate way, a video with the rust comparison 😫
will do! If you are on twitch you will see that I am getting close.
Possibly explanation for why the memory optimizations made things faster: it may have actually made things slower overall - but the program is going to run with fewer or shorter interruptions by the garbage collector, which is probably why the blue bar goes up. 🙂
that is my general consensus. An "easy" to validate this theory would be to make this server run in the browser (i already have sockets sort of abstracted away as is) and build a simple socket impl to feed in fire commands. From this i will be able to use the performance tab in chrome debugger. I could export the data to json and sum up time spent in GC.
Also, apparently in node i can pass v8 flags to the engine and get tracing for free, but I don't know how to do that :)
Thanks i am exited for rust.
I AM TOOO!!!!
That was smooth gonna build something similar in kotlin don't hate me for using jvm :)
hah! I have always been curious about kotlin.
nice video prime!! Love to see this in rust.
I like perf videos, especially comparison.
The doc of programming
yayayayaya
I love graph.
I really love all videos. :D
I would like a video that you installed your dotfiles from zero or a video about arch linux (is that your OS?)
If I miss some english grammar, hope you can forgive me blazingly fast
i definitely do not use arch. I have kids which has been disallowed by the international linux committee to use Arch Linux.
I love this kind of content
95% of all other youtube programming channels that I used to follow became soydev tier after I discovered this channel. Awesome shit man, and thank you for teaching me about flame graphs! #bLaZinGlyFaSt
Yayayaya! One of my first goals of the channel is to stop beating around the bush. GET TO THE CONTENT. #BlAzInGlYfAsTsOyDeV
Coconut oily video as every time 🌝❤️ but can we blessed with the prime knowledge how to generate those frame-graphs ?
look at the description. There is a link. It links to the repo where I have the exact steps I used to run the flamegraphs.
@@ThePrimeagen thanks prime 🌝
I've never turned a notification bell on before =O
I identify as a blazingly fast apache helicopter
you too watch the game theorist.
This is like really really really interesting, i want your knowledge
Yes we love this content, we love to learn how to make our apps go brrrrrrr
awesome! Hopefully that sweet little data structure I threw in the mix was great :)