Duration 8:21

PROOF JavaScript is a Multi-Threaded language

225 041 watched
0
14.5 K
Published 4 Aug 2023

Learn the basics of parallelism and concurrency in JavaScript by experimenting with Node.js Worker Threads and browser Web Workers. #javascript #programming #computerscience Upgrade to Fireship PRO https://fireship.io/pro Node.js Worker Threads https://nodejs.org/api/worker_threads.html Check out @codewithryan /watch/QxN1Z3_4mI_41

Category

Show more

Comments - 522
  • @
    @daedalus50709 months ago I could feel my brain trying to stop me writing what i knew was an infinite loop but i did it anyway. I trusted you jeff! 1451
  • @
    @AlecThilenius9 months ago Fun nerd trivia:
    - a single cpu core runs multiple instructions concurrently, the cpu core just guarantees that it will appear as if the instructions - a single cpu core often executes instructions totally out of order, this isnamed " out of order (o)
    - a single core also executes instructions simultaneously from two different threads, only guaranteeing that each thread will appear as if it ran serially, all on the same shared hardware, all in the same core. This is called
    and we haven' t even gotten to multi-core yet lol. I love you content jeff, the ending was gold!
    .
    ...Expand
    307
  • @
    @elhaambasheerch70589 months ago Love to see jeff going in depth on this channel, would love more videos like this one. 57
  • @
    @WolfPhoenix09 months ago That chef analogy about concurrency and parallelism was genius. Makes it so much easier to understand the differences. 58
  • @
    @RedlinePostal9 months ago Also when we saythat means " one-core at a *time*" computer kernels are concurrent by default, and the program' s will actually be constantly shifting to different cpus, as the kernel manages a queue of things for the processor to do. Not too unlike the asynchronous system that javascript has, kernel will break each program you' re running into executable chunks, and has a way to manage which programs and code get more priority. ...Expand 242
  • @
    @JThompson_VI9 months ago Moments like , the short memorable description of callback functions, is what makes you a great teacher. Thanks man! 94
  • @
    @ra2enjoyer7089 months ago It' s a pretty good overview on how much more of a clusterfuck the code becomes once you add workers to it. And it didn' t even get to the juice . ...Expand 197
  • @
    @srejonkhan9 months ago To see how all of your cores utilizing, you can change the graph from 'Overall utilization' to 'Logical Processor' just by right clicking on the graph -> Change graph to -> Logical Processor. .. ...Expand 25
  • @
    @yss649 months ago Thanks for shouting out code with ryan! That channel is criminally underrated. 4
  • @
    @BRBS3609 months ago I' d like to see a video on javascript generators and maybe even coroutines. 36
  • @
    @nomadshiba9 months ago Talking about
    data oriented design always helps.
    2
  • @
    @boris---9 months ago Task Manager --> Performance tab --> CPU --> Right click on graph --> Change graph to --> Logical Processors 2
  • @
    @ahmad-murery9 months ago It would be nice if you right click on the cpu graph and *change graph to > logical processors*, so we can see each thread separately.
    thanks!
    28
  • @
    @EdgeGaming9 months ago Lots of comments about memorable descriptions, shoutout to the thread summary at . Your conciseness is excellent. 1
  • @
    @user-fed-yum9 months ago That ending was possibly one of your best pranks ever, a new high watermark. 1
  • @
    @7heMech9 months ago Really cool, i actually saw the other video about nodejs taking it up a notch when it came out. 1
  • @
    @wjlee70039 months ago Although it' s called concurrent, schedulers still can only work on one task at a time. It will delegate a certain amount of time to each task and switch . ...Expand 5
  • @
    @AntonisTzorvas9 months ago Aside from the outstanding quality, this ending was quite funny and hilarious! Keep it up, your content is top. 1
  • @
    @avsync-live9 months ago Little known fact, you can also do dom related operations on another thread. You have to serve it from a separate origin and use the header, and load the script in an iframe. But you can still communicate with it using postmessage, and avoid thread blocking with large binary transfers using chunking. This is great for stuff that involves video elements and cameras.
    i use it to move canvas animations (that include video textures) off the ui thread, and calculating motion vectors of webcams
    .
    ...Expand 37
  • @
    @deneguil-16189 months ago Just a heads up for your cpu; the 12900k doesn' t have 8 physical cores, it indeed has 16, 8 performance and 8 efficiency cores, the performance cores . ...Expand 76
  • @
    @kiprasmel9 months ago The `threads` package makes working with threads much more convenient. It also works well w/ typescript. 1
  • @
    @junama9 months ago Good vdeo!
    next time change the cpu graph with right click to see each threat graph.
    hope it helps!
    16
  • @
    @dzhaniivanov58379 months ago I watched a similar video early this year, but your way to deliver content is amazing, keep going.
  • @
    @Bell_4203 months ago The cook analogy was great and i now understand.
  • @
    @maxijonson9 months ago My brain: dont run it
    8 years of programming: dont run it
    the worker thread registering my inputs to the console as i type it: dont run it
    jeff: run it.
    *runs it*.
    7
  • @
    @Ihavetoreturnsomevideotapes9 months ago Ayo, was learning event loop and had a bit of confusion about performance b/w single and multithreading and jeff just posted the video at the right time.
  • @
    @AlexEscalante9 months ago Wow! Just yesterday i was watching some videos about worker threads because i will use them to speed up the ui in my current development. 1
  • @
    @TeaBroski9 months ago It' s like you read my client' s requirement and came into support. 3
  • @
    @yournerdiness31359 months ago This video is the embodiment of " why do something easily when you could spend hours unsuccessfully making it faster" 4
  • @
    @DranKof9 months ago I tried the while loop thing and somehow my computer became sentient. Y' all should try that out. 2
  • @
    @abhijay_hm9 months ago With the amount of time i' ve spent on this video because of the while loop, even the algorithm knows who my favourite youtuber is. 1
  • @
    @hyper_channel9 months ago a small detail at your i9 has 16 physical cores not 8. Only half of them have hyperthreading (because there are 2 types of physical cores in that cpu). That's why it has 24 threads instead of 32 .. ...Expand 8
  • @
    @robertjif63379 months ago Thanks, now i know what script i should include in my svgs. 1
  • @
    @zeta_meow_meow3 months ago Seeing my cpu throttle and core usage rise in realtime was impresive:
  • @
    @PlayWithNiz9 months ago I' m thinking out loud here, but have a genuine question - could you use workers combined with something like husky to do allchecks at once?
    for example, i may have a largetest suite, followed by a large e2e test suite, along with code quality checks and so on. All of which are ran in sequence potentially taking upwards of a few minutes to complete.
    could workers be used to run these jobs together at once?
    .
    ...Expand 1
  • @
    @DumbledoreMcCracken9 months ago Each value should be a random value, and you should sum them in the end to ensure the compiler / interpreter does not optimize all the work away because it detected that you never used the values. 1
  • @
    @MrSovr9 months ago Yea tried everything, still frozen. Any additional advice for fixing it? 1
  • @
    @HedleyLuna9 months ago I did use this back in 2018. I don' t know how much it improved, but error handling was painful. Also, when you call postmessage( v8 will serialize apart from that, you should never share data between threads, that' s an anti-pattern. ...Expand 1
  • @
    @MegaMech9 months ago A single x86 core can actually run more than one command at a time. And the n64 can run 1. 5 commands at a time when it uses a branch delay slot. 1
  • @
    @wusluf9 months ago Adding more cores might still provide gains in a vm scenario depending on the hypervisor. As long a your vm isn' t provisioned all physical cores the . ...Expand
  • @
    @RajitRoy_NR9 months ago What are some of the useful libraries which help or use workers? Like partytown or comlink. 1
  • @
    @duckysolucky49619 months ago Thank you, now i' m stuck in the vim and in the browser. 3
  • @
    @Sowagware9 months ago Do you want to run() the jobs or double the workers and give it to the next run()?
  • @
    @adaliszk9 months ago You can also pass initial data without needing to message the thread to start working, however, that one i feel like its better to use for initialization like connecting to a database.
  • @
    @ninjaasmoke9 months ago People watching on phone:
    that level of genjutsu doesnt work on me.
  • @
    @JeremyAndersonBoise9 months ago Spawning workers in node is not new, but support for web workers in browsers is comparatively new. Good shit man.
  • @
    @JeremyThille8 months ago Niice we have the exact same machine! And thanks for the video!
  • @
    @VileEnd9 months ago Love it, we are already doing that with our lambdas - cause why not use the vcores when you got them. 1
  • @
    @ko-Daegu9 months ago concurrency incorporates parallelism
    what you should is asynchronism
  • @
    @Bossslime9 months ago I remember when i first learned workers, i didnt realize k could use a separate js file so i wrote all of my code in a string, it was just a giant string that i coded with no ide help. That was fun. 1
  • @
    @tracevandyke20099 months ago Ok so i did the while( true ) loop and after unplugging my computer and plugging it back in, it still didnt unfreeze my browser. Should i try deleting system32 next?
  • @
    @earthling_parth9 months ago I' m struggling really hard with some of our developers using nodejs workers in containers inenvironment. I' m on the don' t have in-depth knowledge of nodejs. In a container based cloud environment, does it still makes sense to get the number of cores of the host os/machine and then create that many workers for doing some compute intensive task? This was utilizing way too much cpu and hitting against their cpu limits so i told them to manually set the number of workers to 4 or 6. Is this the correct approach? Can someone with more knowledge about nodejs and it' s best practices in containerized environment help me out here? Thanks in advance. ...Expand 1
  • @
    @jack1713809 months ago I wonder if there are things like mutex locks to help with theof shared resources? 1
  • @
    @iandrake46839 months ago I ran ur codz and mi coputer melted. Weer do i submit claim?
  • @
    @DarthNithin9 months ago I wish you showed the cpu usage on each logical processor on task manager instead of the overview.
  • @
    @rmlmax9 months ago my tab is still not responding. What should I do?
  • @
    @lionbryce101019 months ago Woulda been cool if you set it to show core usage on taskmgr. 1
  • @
    @Xe0549 months ago Fireship, the " s" sounds in your video sound really harsh. Consider using a de-esser plugin or a regular compressor plugin and your stuff will sound fantastic. Cheers.
  • @
    @markopolo22249 months ago Man i been wanting something about workers for so long.
  • @
    @akashrajpurohit979 months ago bro really doubled it and gave it to the next thread
  • @
    @MuhammadbinYusrat9 months ago Doesn' t out of order execution try to divide work to multiple threads on its own?
  • @
    @TonyAlcast9 months ago I'm still amazed at how you find such accurate images as the one at
  • @
    @AbdulRehman-ee8zc9 months ago I was aware my browser will stop working due to while(1) then also i did it
    now you tell me how to fix it for internet explorer because closing i am using windows 7. ...Expand
  • @
    @Quamsi9 months ago I have had hours long lectures in college level programming classes on the differences between concurrency and parallelism and the first 3 minutes of this . ...Expand 33
  • @
    @zimin50769 months ago I have a 8 core cpu, i open 8 tab with 8 while true loop, will my computer die?
  • @
    @AchwaqKhalid9 months ago Dude the 12900k has 16 physical cores (8p+8e) and a total of 24 threads since only the p cores have hyper-threading 1
  • @
    @joebgallegos9 months ago I recently did a little side project where i needed to use a worker in a web app. The gist of the project is given a winning lottery number, how many quick picks or random tickets would it take to finally hit.
  • @
    @hasipTimurtas5 months ago After the loop my laptop turned to fireship, is this how you increase your fans?
  • @
    @wlockuz44679 months ago I thought worker threads were virtual threads. You learn something new everyday! 2
  • @
    @BoloH.9 months ago I once made a volume rendering thingie with three. Js and it really, really benefited from web workers, especially interpolation between z slices. 4
  • @
    @jugurtha2929 months ago in , how is swift that slow, its static and compiled and does not use garbage collection.
  • @
    @dave60129 months ago Mr jeff will you do one on creating a websocket server in node js?
  • @
    @fruitsnack18129 months ago Wait, what about async/await and concurrency. Is it same thing in his picture?
  • @
    @JellySword89 months ago If using 16 workers causes 100% cpu usage than how is the os still able to do anything? Is it because each thread is also using concurrency?
  • @
    @Martin-kt8sz9 months ago Did anyone find a way to force close a tab on arc?
    every time i get an infinite loop i have to restart the whole browser.
  • @
    @bruc15559 months ago Please help, i have been trapped here for 5 years, the browser still won' t let me out. 1
  • @
    @nullternative9 months ago I just recently experimented with the offscreen canvas handling rendering on a separate worker thread. Pretty cool. 5
  • @
    @gr.43809 months ago Love how you tell us to leave a comment if it' s locked like we can even do that.
  • @
    @MysteryMixerMan9 months ago Are there any major baseline costs that need to be considered when spinning up workers? Start time, considerable ram etc)
    thanks for the content.
  • @
    @jimbowers12989 months ago Unlimited view times! Awesome! What a great video! 2
  • @
    @nadavgover60179 months ago My browser is still stuck with watch time overflow error. Send help.
  • @
    @dan-cj1rr9 months ago No clue if this could be an interesting video, but teach us about how to deploy on different environment ( ex: testing, production) as a junior i always . ...Expand
  • @
    @landscapesandmotion9 months ago Elixir is faster than i thought and getting faster with the new jit compiler improvements.
  • @
    @aravind.a9 months ago How it is different from cluster module?
  • @
    @DamonMedekMusic9 months ago I' ve used the web worker api to filter multiple arrays at once and it' s okay but it is very unintuitive to use and it could definitely be improved . ...Expand 1
  • @
    @0Smile09 months ago Hello,
    it' s been 23 years. My chrome tab is still not responsive.
    please send help.
  • @
    @fatzzke9 months ago Huh your i9 has 16c/24t but it still spikes to 100% at 16threads. Does windows not count the e-cores or does it go to 100% because hyperthreading on the same operation usualy doesnt work.
  • @
    @RegalWK9 months ago Every async thing you do goes to micro task or task queue, and every single one of them is executed on different thread, and once its done it goes back a web workes once are done also goes to main thread to the callstack. ...Expand 5
  • @
    @themax2go8 months ago Unplugged puter didn't work (fix issue with unresponsive browser). kekw
  • @
    @AnwarulIslamYT9 months ago Javascript is referred to high level, single threaded, garbage collected, interpreted || jit compiled, prototype based, dynamic language with a, non-blocking event loop. 1
  • @
    @victorpinasarnault91359 months ago Is workers api the same thing as web workers?
  • @
    @Emil_969 months ago If every thread is independent from each other e. G. With the browser window having its own thread, how come that if you encounter an issue in one thread, . ...Expand
  • @
    @mohitnagpal9 months ago I was asked the same question for an internship interview in 2021 whether js is multi threaded or not and i said yes because of worker threads. The interviewer said no, it is not and hung up the phone: 1