How I Made JavaScript BLAZINGLY FAST

Sdílet
Vložit
  • čas přidán 16. 10. 2022
  • I did a fun experiment to expose the cost of GC
    Links
    V8 v8.dev/blog/high-performance-...
    Code: github.com/ThePrimeagen/yt/bl...
    Twitch
    Everything is built live on twitch
    Twitch : bit.ly/3xhFO3E
    Discord: discord.gg/ThePrimeagen
    Spotify DevHour: open.spotify.com/show/4MLaDrQ...
    Editor
    All my videos are edited by Flip. Give him a follow! / flipmediaprod He is also open to do more editing, so slide deeeeeeeeep into his dms.
    Join this channel to get access to perks:
    / @theprimeagen
    Links
    Linode: linode.com/prime
    / discord
    Twitch: / theprimeagen
    Insta: / theprimeagen
    Twitter: / theprimeagen
    VimRC & i3: github.com/ThePrimeagen/.dotf...
    Keyboard 15% off bit.ly/Prime360 USE CODE PRIME360
    #vim #programming #softwareengineering
  • Věda a technologie

Komentáře • 448

  • @uhN0id
    @uhN0id Před rokem +1187

    I'm pretty sure that Prime is talking about my code when he says garbage collection.

    • @paulheisner
      @paulheisner Před rokem +46

      Holy sh**, i had to laugh out loud reading this

    • @ayoub.k
      @ayoub.k Před rokem +10

      Your comment wins.

    • @asedtf
      @asedtf Před rokem +8

      My collection of garbage is certainly slow.
      This statement is true in every possible interpretation

    • @ThePrimeagen
      @ThePrimeagen  Před rokem +221

      its beautiful
      but its garbage

    • @uhN0id
      @uhN0id Před rokem +38

      @@ThePrimeagen I thought it was what's on the inner scope that counts :(

  • @artifishul
    @artifishul Před rokem +73

    Big fan of the more technical stuff like this

  • @stasgavrylov
    @stasgavrylov Před rokem +304

    Man, you should definitely make more of those deep-dives, you have so much knowledge to share.
    If you could also drop a link to this code in the description, that'd be really useful.
    Thanks for the great tip!

    • @ThePrimeagen
      @ThePrimeagen  Před rokem +71

      i will! for you, here you go github.com/ThePrimeagen/yt/blob/master/is-javascript-slow/test.js

    • @stasgavrylov
      @stasgavrylov Před rokem +21

      @@ThePrimeagen 👈😎👈

    • @Draxen
      @Draxen Před rokem

      Agreed, straight 🔥

    • @HuxleysShaggyDog
      @HuxleysShaggyDog Před 11 měsíci

      Based

  • @Psy45Kai
    @Psy45Kai Před rokem +176

    Love auch JS deep dives. I am myself a C++ and now (partially because of you) Rust developer and like this performance stuff 😁
    Since I just start using JS I like listening to JS ninjas like you are. This is much more interesting than most low level JS stuff on YT 😁
    Thanks for your high octane videos ✌️

  • @cal3461
    @cal3461 Před rokem +19

    Awesome timing. Just learned about how Rust manages memory today so this will be a nice contrast!

  • @blackfrog1534
    @blackfrog1534 Před rokem +26

    YES Primeee back at it with the technical stuff. For me this is your best type of content and the streams that lead up to it are so much fun!

    • @ThePrimeagen
      @ThePrimeagen  Před rokem +8

      yaya!
      I do love the technical content and i think its super fun.

  • @lisyr4918
    @lisyr4918 Před rokem +38

    I am a junior dev, but even understanding only about 50% / 60% I am learning so much watching your videos, thanks for this incredible quality videos!

    • @SiisKolkytEuroo
      @SiisKolkytEuroo Před rokem

      Is there something specific you did not understand about the video, I'd be happy to explain

    • @odorlessflavorless
      @odorlessflavorless Před 9 měsíci

      @@SiisKolkytEuroo I did not even the problem statement here. Is it about tweaking the code in a way the V8 engine does not run garbage collector ?

    • @SiisKolkytEuroo
      @SiisKolkytEuroo Před 9 měsíci

      @@odorlessflavorless yeah I suppose you could say that. Or, writing your code in a way that doesn't do as many allocations and doesn't leave much garbage behind

    • @vin1208
      @vin1208 Před 8 měsíci

      @@SiisKolkytEuroo bro tbh i did not understand the first function, the closure i do not understand it, never used it in real life in what case scenario would that function be used so from that i barely understood the whole video, i dont even know class components and what was he trying to do with all that props1 props2 props3 and the vocalbulary he used i didnt understand most of it, im self taught so i only understand code but not terminology.

  • @jordanasghar6419
    @jordanasghar6419 Před rokem +1

    My favorite type of videos from you! I use JS all the time and see the spread pattern constantly, never thought to consider the GC impact under the hood but makes total sense!

  • @alexandersemionov5790
    @alexandersemionov5790 Před rokem +41

    I love it. Object pool is quite a popular technique in game engines to reuse npcs and so on. Please continue with this format

  • @scottiedoesno
    @scottiedoesno Před rokem +39

    Really enjoy the technical stuff! As someone who has more than a casual relationship with JS, these kind of engaging technical analyses are super useful on a very regular basis

  • @Zzznmop
    @Zzznmop Před rokem +1

    It’s crazy that I’ve watched your channel on twitch and CZcams for years and learn something new every time I listen
    Thank you!

  • @jamesfoley4426
    @jamesfoley4426 Před rokem +6

    I really enjoyed this video and yes I would like to see more content where you do a code review just like this. CZcams is filled with junior developer content. It is hard as an intermediate to find content that improves your skill set/skill level. I think with your knowledge base your technical review of code is extremely beneficial.

  • @aaronroethe1010
    @aaronroethe1010 Před rokem

    love all your videos, keep up the technical side and I love your Go content!

  • @conradbuck2414
    @conradbuck2414 Před rokem +18

    I wrote a streaming regex engine and it hammers the GC pretty hard because it needs to create an object for each state it passes through, and on any real text and expression it passes through a lot. I studied its perf because I thought I'd have to pool the state objects, but instead profiling showed that I was only spending ~20% of my time doing GCs. That's because v8's generational garbage collector is optimized for the collection of objects that are small, short-lived, and have a common structure/shape. Engineers should not shy away from using those kinds of objects!

  • @chrishamilton1728
    @chrishamilton1728 Před rokem +44

    I'd love to see a conversation between you and the React devs about the "Immutable" philosophy.
    So many new objects, every single render, it hurts...

    • @ThePrimeagen
      @ThePrimeagen  Před rokem +18

      probably could squeeze quite a bit out on the server if they stopped

    • @chrishamilton1728
      @chrishamilton1728 Před rokem +36

      ​@@ThePrimeagen React's whole change detection system is built around shallow diffing two objects sooooo.....
      But it's not a design flaw, because it makes your code *_PURE_* 😇🙏
      pure garbage

    • @marcusrehn6915
      @marcusrehn6915 Před rokem +16

      ​@@chrishamilton1728 Immutability is a sound concept that is. There are a number of ways to implement it in a far more performant manner. Sadly, javascript arrays and objects have pretty much none of the characteristics needed.
      There are libraries like Immutable JS, but that also falls short because no library is going to pass us an immutable list, for example after a database query. So you would have to make at least one copy of the array when converting to Immutable.
      How about we just skip JS on the server, at least where performance matters?

    • @pm1783
      @pm1783 Před rokem

      @@marcusrehn6915 agreed

    • @danielchettiar5670
      @danielchettiar5670 Před rokem

      @@chrishamilton1728 Imo vdom is unnecessary with modern hardware. If they took that out, react dx would be much better and they also wouldn't have to do the diffing.
      But that's a monumental change that's never gonna happen. Good that we have other great open source ui libs

  • @82TheKnocKY
    @82TheKnocKY Před rokem +1

    I love this!
    This is the data based advanced stuff that no one else on CZcams really does. With realworld fang experience to back it too!

  • @klegsy
    @klegsy Před rokem

    These are the primeagen videos I enjoy the most! Keep them coming

  • @krombopuloslincler4849
    @krombopuloslincler4849 Před rokem +5

    Please do these type of videos more. Love it

  • @daveisradicle
    @daveisradicle Před rokem

    Great video, super smart way of showing off GC operations and how to work around them.

  • @filipecrosk
    @filipecrosk Před rokem

    Mna, these kind of content is all I need!! Thanks for sharing.
    Performance, performance, performance!!! Learn how to dig inside the runner and understand what parts of your code is taking longer and then debug to get it better is what everyone should learn. I know it's advanced for a lot of people, but learn how to debug is an art that we all should give more attention to.
    Again, I'm 1000% for more content like this!!!

  • @MrBaudin
    @MrBaudin Před rokem +5

    It was a great video, i would like to see more content like this. My opinion on the vid was that the setup could be shorter, the explanation of the code a bit longer and the ending was perfect!
    Performance is a difficult topic and these videos really help explain your thought process, please make more of them.

  • @typeer
    @typeer Před rokem

    Man I'm so grateful for you communicating this stuff in 10 min chunks so good ty sir

  • @zuzuz18
    @zuzuz18 Před rokem +1

    Super high quality video. One of your best yet

  • @fyndor
    @fyndor Před rokem +3

    Hey Mr./Ms. video editor, loved the "Not sure what he wanted me to do here lol" :D I always forget most of the good content creators have an editor making these guys much better than they would be on their own. You are doing a good job btw, whoever you are.

  • @ffshawon1287
    @ffshawon1287 Před rokem +2

    It really worked for me after I look and try some tutorials, yours is the one that worked. Owe you a lot.

  • @ds_7
    @ds_7 Před rokem +1

    I loved this, I love your technical videos, MOAR CODE!!!

  • @chrisjames278
    @chrisjames278 Před rokem +18

    Love these walk throughs. Great to have more

  • @thecoincritic
    @thecoincritic Před rokem

    Thanks for the content. I've been working on how to rework blockchains without so much promise dependency...love these thought experiments. Best...hope the Volcano experiment works out!

  • @_Aarius_
    @_Aarius_ Před rokem +1

    Lots of the time people are writing code that's more IO bound than CPU bound, but it's still useful to know these tricks for the areas where you are in a hot CPU loop

  • @velho6298
    @velho6298 Před rokem

    Great stuff! Interesting to listen these more technical topics.

  • @Rihsto
    @Rihsto Před rokem

    Oh Prime these technical JS deep dives are fire 🔥🔥🔥

  • @leptanian
    @leptanian Před rokem +17

    Personally I like the more technical videos you make. These walkthroughs and explanations are extremely valuable imo.
    And as always the editing is top-notch, Flip is the man.

  • @dulanjala
    @dulanjala Před rokem

    this is exactly the kind of content needed, deep dive into certain things...

  • @benjaminkindle1841
    @benjaminkindle1841 Před rokem +2

    The amount of energy this guy can summon while talking about such dry topics is truly impressive

  • @m.minkov
    @m.minkov Před rokem

    I have pressed all the buttons! I love these videos, I am incredibly interested in internals and how performance can be increased. Please dish out more!

  • @calcs001
    @calcs001 Před rokem +1

    Love this deep dive.. keep it technical, go deeeeeep sir, deeep!

  • @poochy661
    @poochy661 Před rokem

    I really like these break-down videos where you show us what not to do and what to do if we want to go BLAZINGLY fast!

  • @nikensss
    @nikensss Před rokem +2

    I also like the technical stuff, feels really nice to understand better what's going on with the tools you are using. Would it also be possible to share a repo with this code?

  • @skiesaboveunlimitedstargaz7316

    Awesome & Greatness!! Very Excellent point!! That's why I sometimes, do not use Promises especially if it takes a lot of time.. But it all depends on the data how you use them and put them onto the objects.

  • @tannishkmankar3998
    @tannishkmankar3998 Před rokem

    IT WORKED, THANKS I'VE BEEN LOOKING FOR THIS FOREVER, BUT NO TUTORIAL COULD EXPLAIN IT AS YOU DID

  • @spitefol5504
    @spitefol5504 Před rokem

    This is the best content I have seen by you, do more like this!

  • @dickheadrecs
    @dickheadrecs Před rokem

    i’m here for this, the hot takes are just gravy

  • @th34lch3m1st
    @th34lch3m1st Před rokem

    I like it. Really inspiring concepts. Keep it up.

  • @abneryang2102
    @abneryang2102 Před rokem

    More of this plz. CI jest runs have been killing us and this was cool to watch with that in mind

  • @TheKiller9696
    @TheKiller9696 Před rokem

    Really enjoyed this content! Would love more videos like this

    • @TheKiller9696
      @TheKiller9696 Před rokem +1

      @ThePrimeagen good job, you are big enough to have bots

  • @wlidWisdom
    @wlidWisdom Před rokem

    i love these king of videos .. keep going !

  • @fluffykeebz
    @fluffykeebz Před rokem

    2:34 -- first time I have been unable to resist the call to hit subscribe. I have subscribed, Daddy Primeagen.

  • @mikebruce6790
    @mikebruce6790 Před rokem

    Awesome video, thanks for making this 🙏

  • @aburner230
    @aburner230 Před rokem

    +1 more deep dives, this is the first video of yours I watched, and it was great

  • @AlphaWatt
    @AlphaWatt Před rokem +1

    Love this stuff Prime

  • @codewithguillaume
    @codewithguillaume Před rokem

    Dude I love this video. Got to watch it again.

  • @alejonanez
    @alejonanez Před rokem +1

    Man, this channel is the best 🎉

  • @c__beck
    @c__beck Před rokem

    I'd love to see one of these showing the Promise issue you mentioned!

  • @joaomachado9105
    @joaomachado9105 Před rokem +2

    your amazing but that editor does wonders too, props to that dude/lady whoever he/she is xD

  • @GovindKumar-pe4lz
    @GovindKumar-pe4lz Před rokem

    Thank you for explaining this thoroughly!

  • @writegoodcode
    @writegoodcode Před rokem +2

    dude love this, please make more technical content like this.

  • @SahraClayton
    @SahraClayton Před rokem

    As a newbie to programming I didn't not have a clue what the Primeagen was talking about, but I still really enjoyed it.

  • @dontpanicyou
    @dontpanicyou Před rokem

    definitely a fan of these JS deep dives.

  • @null_bite
    @null_bite Před rokem

    Love thiss .. keep em coming!! 😍

  • @marcolerena456
    @marcolerena456 Před rokem

    Hey Prime, I checked out your course on Frontend Masters, but I don't wana pay for their monthly membership just for your courses - I'd rather just buy courses from you. Also, I would really love a comprehensive backend course (in Js(ts) and/or rust) from you. You're one of the most entertaining and technically competent programmers on youtube. I'd love to learn from you!

  • @ErmandDurro
    @ErmandDurro Před rokem

    Really great content. Love it 😀

  • @markclynch
    @markclynch Před rokem

    Love the more technical deep dives

  • @ethSiberianDex
    @ethSiberianDex Před rokem

    I love these science adjacent videos, they are like reading scientific articles but more fun

  • @jogofin4939
    @jogofin4939 Před rokem +1

    I'd like to see a more in-depth breakdown of how garbage collection works as pertains to promises, and how you circumvented promises altogether. Good stuff

  • @erikslorenz
    @erikslorenz Před rokem

    This is great thanks. I usually don't worry too much about it since if I'm using JavaScript it's not in a performance = money scenario

  • @harrybilsonia
    @harrybilsonia Před rokem +1

    Prime!! Sending you some algorithmic clues to show more code

  • @alexcasillas
    @alexcasillas Před rokem +2

    Great video!! Though I’m extremely curious about the refactor of the promises and that performance gain, can you elaborate more on it apart from GC taking so much time? I’d love a video about this :)
    Great job, love your channel 🔝

    • @ThePrimeagen
      @ThePrimeagen  Před rokem +3

      I'll do a video on it.

    • @Kurimson
      @Kurimson Před rokem

      Yea, me too. Definitely Left me wanting more 😊.

  • @changuchito69
    @changuchito69 Před rokem

    love this type of videos!

  • @taylorallred6208
    @taylorallred6208 Před rokem +1

    I’ve heard that reference counting is a good strategy for UI’s. Would this mean that front end apps could get better performance with Rust and Wasm using ref counting (as wasm catches up with V8)?

  • @willl0014
    @willl0014 Před rokem

    I didn't understand half of it, but this was a pretty interesting video. I think i will look into this more. Thank you for sharing

  • @syakhiskk
    @syakhiskk Před rokem +1

    Genuine q's, are there any benefit of using ts/js in backend? I always thought that if I wanted performance, I would use something else.

  • @DIEZ919191
    @DIEZ919191 Před rokem +1

    DAMN! Finally I found someone who teach like a savage! Usually I find myself sleeping right after couple of minutes of *explaining* something, here in a turn, I want to break my fckn retina display like rock star breaks his guitar! BTW didn't understand how you implemented test example, but it doesn't matter!

    • @ThePrimeagen
      @ThePrimeagen  Před rokem

      hah, well, i do like teaching at break neck speed

  • @amirhoseinfarhadi2268
    @amirhoseinfarhadi2268 Před 3 měsíci

    We love this type of videos 😍😍

  • @mekhoinfo2118
    @mekhoinfo2118 Před rokem

    the deepest video about JS I've ever watched lol, now I know that I have a long road before me to become like you @ThePrimegen

  • @gustavcoetzee5018
    @gustavcoetzee5018 Před rokem

    Love this content. Learn good stuff

  • @tarotv4609
    @tarotv4609 Před rokem

    Thank you for this! Super cool video! A+++

  • @petrpechkurov3095
    @petrpechkurov3095 Před rokem

    Thank you, Mr. ThePrimeagen!

  • @michaelross3061
    @michaelross3061 Před rokem

    Yay on the technical vids/amount of code. Made happy brain chemicals

  • @mateuszciupa8141
    @mateuszciupa8141 Před rokem +1

    that's why pure functions are advised and returning callbacks is disadvised

  • @thanhn2001
    @thanhn2001 Před rokem

    More please. I like this kind of stuff.

  • @RafaLeyvaRuiz
    @RafaLeyvaRuiz Před rokem

    I liked the video only because you send me to read the description and the way you requested was funny 😂

  • @earthling_parth
    @earthling_parth Před rokem +1

    I LOVE it! Please more technical stuff! PRIME, I AM SENDING YOU THE ALGORITHMIC SIGNALS PRIMMEEEEE!!!!

  • @giacomogagliano1526
    @giacomogagliano1526 Před rokem

    you are way too funny =) and also smart!! great job!!

  • @yumyum7196
    @yumyum7196 Před rokem

    Please!!!! More technical videos like this one 🙏🙏🙏

  • @kiernanacuesta1417
    @kiernanacuesta1417 Před rokem

    This is great, thank you!

  • @JRasmusBm
    @JRasmusBm Před rokem

    Favorite vid so far 😃

  • @TomGeogecko
    @TomGeogecko Před rokem

    Prime always missing the actual place of like button. Every time he says "it's there just press it" he points to some random direction :D

  • @TayTayChan
    @TayTayChan Před rokem +3

    Yeah, tech-heavy videos are great. Code is life

  • @bryanchulander
    @bryanchulander Před rokem

    So informative. Thank you

  • @nitheeshraajar393
    @nitheeshraajar393 Před 10 měsíci

    How/Where do you start learning all this stuff???? So much in-depth knowledge and its really fascinating. Makes me wanna go indepth too

  • @user-pz9qh9rj8z
    @user-pz9qh9rj8z Před rokem

    thanks a lot!!! so nice reverb

  • @LeandroCoutinho
    @LeandroCoutinho Před rokem

    Amazing stuff! For more profiling like that!!!

  • @venkateshhariharan4341

    These kind of videos are educational thanks

  • @wforbes87
    @wforbes87 Před rokem

    actual technical content about a language that no one really thinks about technically is the true performance optimization involved here

  • @lopoyadriang.9114
    @lopoyadriang.9114 Před rokem

    Thank you, it works perfect!

  • @farrellraafi1301
    @farrellraafi1301 Před rokem

    I actually experimented with this when I try to port RPython to wasm. Basically leaking all the memory to do 1 full stack execution, and then shrink the memory back to the initial state in the next tick (setImmediate or setTimeout) is tons faster than applying GC algorithm and libraries even bigger one like boehm.

  • @DanielTateNZ
    @DanielTateNZ Před rokem

    This is the only video you made I have enjoyed.

  • @arshadpakkali
    @arshadpakkali Před rokem +2

    Would really appreciate it if you can make a video on why/how/when ditch promise to better performance

  • @yx4292
    @yx4292 Před rokem +1

    The idea of an object pool in a library like fastly sounds like (if I understand correctly) it would be incredibly easy to misuse, because the user needs to be very careful when to release the request object. On the one hand, if you release it too early/hold onto the object for too long and (for example) use it across an await point, the JS engine may well execute another request and it could reuse the released object (and effectively write request data of the new request to the object which is still in use by the other request). Then once it goes back to executing the old request, it has all the request data from the new request. On the other hand if you forget to release the object, it "leaks".This sounds almost like manual memory management but in JS

    • @taragnor
      @taragnor Před rokem

      Yeah it's exactly like manual memory management in JS. And you run into all the pitfalls of manually memory management like in C, where you can have to worry about double free and making sure you actually don't have any more pointers to the old object when you toss it back into the pool. Otherwise you're going to have some seriously weird bugs as you could have multiple parts of your program using the same object, when in reality you want those objects to be different.
      You really need a very good reason to want to use a scheme like this, where for whatever reason you have a very performance critical section and need to take advantage of this. Though given the pitfalls of doing this code and maintaining it, this approach should be a last resort.

  • @cbbcbb6803
    @cbbcbb6803 Před rokem

    Still interesting, still funny, still a great teacher.