Benchmarking JavaScript Is A Mess

  Рет қаралды 43,702

ThePrimeTime

ThePrimeTime

Күн бұрын

Twitch / theprimeagen
Discord / discord
Become Backend Dev: boot.dev/prime
(plus i make courses for them)
This is also the best way to support me is to support yourself becoming a better backend engineer.
LINKS
byteofdev.com/...
By: Jacob Jackson | asyncbanana.dev/
Great News? Want me to research and create video????: / theprimeagen
Kinesis Advantage 360: bit.ly/Prime-K...
Get production ready SQLite with Turso: turso.tech/dee...

Пікірлер: 121
@theftking
@theftking 3 күн бұрын
Bro never benchmark JS. I know a guy who benchmarked JS. He died. Was it because he benchmarked JS? Who knows, but to be safe, I wouldn't.
@orionh5535
@orionh5535 3 күн бұрын
Studies show that javascript have a 100% mortality rate over 120 years!
@tjsr
@tjsr 3 күн бұрын
MOST JS/TS developers I know don't even know how to (or even have never used) cover coverage or profiling tools at all, ever. Benchmarking is so far to the right of that, I can't see it becoming common practice for modern devs any time soon. For those of us who learned our Software Engineering craft 20 years ago, this was all "standard practice" :( I would dare say that at least 80% but probably 90% of modern devs wouldn't know how to produce or use a heap dump of a process, and use that to replicate issues and help with benchmarking what happens when the process has got to the state they've been given as an example.
@no_name4796
@no_name4796 3 күн бұрын
Hey prople only die on planet earth, and planet earth is the only planet which javascript has reached (for the love of all that's holy, i will kill a god if the mars rovers have js code in them) Was it because of js? Who knows. But to be safe, i wouldn't use js
@outsider1st
@outsider1st 3 күн бұрын
Ok boomer
@hanifarroisimukhlis5989
@hanifarroisimukhlis5989 3 күн бұрын
@@tjsr Dude, i've been programming for over a decade and the amount of benchmark, coverage, or profiling i do is zero. I don't even use debugger more advanced than printf/console.log/etc. Modern programmer are so cucked with smart IDEs, debugger, and now AI assistant. If your code is good, it'll run reasonably fast. The only time you need to optimize is to use new features like SIMD, GPU, etc.
@matelocopoco
@matelocopoco 4 күн бұрын
remove benchmarking from the title
@BarneyBarney-y5l
@BarneyBarney-y5l 4 күн бұрын
You could also remove JavaScript from the title and it works.
@mithrilsb
@mithrilsb 4 күн бұрын
@@BarneyBarney-y5lyou could also just leave “mess” as the title and it works
@user-sb5vt8iy5q
@user-sb5vt8iy5q 3 күн бұрын
i love Javascript
@jonesaa2746
@jonesaa2746 3 күн бұрын
Notice title is JavaScript and not typescript 👀
@lukalakuka
@lukalakuka 3 күн бұрын
​@@jonesaa2746 ????? TypeScript ->*transpile to JavaScript* -> same speed.
@lcarsos
@lcarsos 4 күн бұрын
I miss these reading an article videos. Helps me keep up with where programming is at when I can't catch live.
@flygonfiasco9751
@flygonfiasco9751 4 күн бұрын
Knuth was NOT talking about optimizing to assembly when writing in C. He was saying programmers should not waste time in optimizing the 97% of their application that doesn’t matter but should also feel enabled to optimize “that critical 3%” that does matter
@flygonfiasco9751
@flygonfiasco9751 4 күн бұрын
He also encouraged compilers to provide feedback about the most expensive operations and that the feedback should be default until turned off
@0xCAFEF00D
@0xCAFEF00D 3 күн бұрын
He's also in a completely different context. The past was different. He's talking about programmers who would write illegible bithacks everywhere. While what goes on now would be considered major algorithm choice failures.
@haph2087
@haph2087 3 күн бұрын
@@0xCAFEF00DSo if the comments on your code aren’t: “//evil floating point bit hack //what the f**k?” You aren’t doing the kind of optimization they were talking about?
@squisherderheld
@squisherderheld 3 күн бұрын
The key point is that you have to measure. But its a pretty general statement, there are obvious exceptions to the rule like when you're writing a high-performance math library. For whole applications there are probably only a couple of places where your really waste performance when you dont optimize.
@duckydude20
@duckydude20 3 күн бұрын
optimizing hot paths. people just don't understand *sigh*
@jeanlasalle2351
@jeanlasalle2351 3 күн бұрын
9:40 Premature optimization is bad in the sense that you shouldn't write bit hacks or SIMD when it may not matter or worse may cause optimization not to happen (sometimes a bit shift may prevent the compiler to do a better job). Of course, that doesn't mean you should write bad code with awful performance. There is something in between: Working, decent but you didn't try to optimize further.
@almicc
@almicc 3 күн бұрын
There's only a few things I consider when thinking about performance: how many times am I iterating over this list, can I organize this data in one step and then process it easier in another, how many network requests am I making, how many promises can I remove/ combine. My company's code base has several places with O(n^3) loops with awaited network requests, repeated twice for no reason, and mongo cursors with batch sizes of 1 that expect to pull thousands of results. I've turned 10 minute functions into 5 second functions by breaking the nested loops, increasing batch sizes, and not waiting for network requests it doesn't care about. There was even a place that made a network request, and then checked a local cache to determine if the network request was needed. Do less, and be most averse to sequential network requests.
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
what does many promises mean? are small async functions combined into 1?
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
What does waiting for network request mean?
@adambickford8720
@adambickford8720 3 күн бұрын
Premature abstraction is roughly 3,432,872 times worse than premature optimizations.
@josephguenther
@josephguenther 3 күн бұрын
Most of my performance issues are me being an asshole and creating a million objects or running some absolute dogshit query.
@Digitalgems9000
@Digitalgems9000 11 сағат бұрын
:D
@ersetzbar.
@ersetzbar. 4 күн бұрын
how does JDSL benchmark?
@carlhandy
@carlhandy 3 күн бұрын
That’s a question for Tom
@enricofischer1330
@enricofischer1330 3 күн бұрын
Tom is a genius.
@olhoTron
@olhoTron 3 күн бұрын
No need to benchmark it, it is already perfect because Tom is a genius
@pianochess1882
@pianochess1882 3 күн бұрын
JDSL doesn‘t support benchmarks. It is in the backlog right after comment support
@markkalsbeek5883
@markkalsbeek5883 3 күн бұрын
Because compilation overhead for each function call is so high compered the execution time, you could argue it runs in constant time.
@amy31337
@amy31337 3 күн бұрын
Also if you call a function over and over in a big for loop, the entire for loop gets compiled with the function inlined inside of it!! And guess what if the dead code and escape analysis passes decides your function is pure enough, it might get optimized out of the loop entirely!!
@MrBreakstuff
@MrBreakstuff 23 сағат бұрын
So since we're talking Donald Knuth, its worth noting that he wrote that paper the year C was created. It does not come up in the article. The thing that's being debated is whether Go_to had any place in structured programming. It's basically defending Dijkstra from his detractors while also giving examples of cases where go_to isn't bad. "Premature optimization is the root of all evil" is simply saying that you can't optimize something that hasn't been run yet, and it is remembered largely because it summed up the case for structured programming. As usual, Donald waxes philosophical about a future optimizing compiler being able to hand code as efficiently as he can, and some of those observations were used later in C.
@lastink444
@lastink444 3 күн бұрын
that FLIPs "microseconds" edit from twitter should've been in this vid. pure gold
@Winium
@Winium 3 күн бұрын
Benchmarks have their time and place in development. You're not going to make random perf changes and hoping that production is going to be faster. Or even, just random changes and hoping prod isn't going to be slower.
@akinfiyinfoluwa
@akinfiyinfoluwa 3 күн бұрын
This guy’s channel is so addictive. And distracting from work 😑
@EmmanuelBright-pq6ji
@EmmanuelBright-pq6ji 3 күн бұрын
lol
@FringeGames
@FringeGames 3 күн бұрын
real
@Mau365PP
@Mau365PP 2 күн бұрын
That is his goal. They are called "Content Creators" for a reason. Your attention = money 💰
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
benchmarking is good, you just need to do it in right way, like using real world load based on what you will do in production, like testing it with your production data, not hello world or for loop. so you know if this one really fits for my spesific use case
@armornick
@armornick 13 сағат бұрын
The bottleneck is usually the network or the database. I always figured the premature optimization thing was about optimizing the things that are actually slow instead of getting stuck on optimizing for loops.
@MaddieM4
@MaddieM4 Күн бұрын
The V8 team making JS fast, leading to the questionable legacy of server-side JS, really does remind me of the historical impact of the cotton gin. Imagine being Eli Whitney, all like "I'm going to reduce the manual effort and human suffering of cotton production!" and accidentally resuscitating the slavery economy in the American south. Because you did too good an engineering job, but without prophetic knowledge of the consequences. Obviously it would be worse to be Whitney, but it probably feels weird to be one of the original V8 alumni watching NPM become a harrowing tower of interdependent neglectware tall enough to blot out the sun.
@superquantumcomputer
@superquantumcomputer Күн бұрын
a nonsense comment
@AlesNajmann
@AlesNajmann 3 күн бұрын
benchmarking is a mess generally
@iam_fidel
@iam_fidel 2 күн бұрын
started learning backend with django and noticed django handles (hides) request and response objects, and i cant get to set them like how node js makes it posible to make callback functions, getting to console log request objects, setting ports and listening to request...... this is making me not want to continue with django as I think I might not learn the fundamentals of http, request, response and other things django hides. Switching to node means i need to learn javascript 🤦‍♂
@TheArrowedKnee
@TheArrowedKnee 2 күн бұрын
Despite JS being a mess, you probably want to get around to learning it at some point anyway, due to how ubiquitous it is.
@BlackAsLight448
@BlackAsLight448 3 күн бұрын
I wrote a cbor implementation in JavaScript for the Deno std, and now I'm slowly opening pull requests with performance improvements.
@MrOboema
@MrOboema 4 күн бұрын
"...and because of that, now we have javascript running on servers. I cant tell if they're the good guys or bad guys." Really? Its freakin' js on a server, man 😑
@callowaysutton
@callowaysutton 3 күн бұрын
It's bad
@carlhandy
@carlhandy 3 күн бұрын
JS was a mistake. JS on the server was a bigger mistake
@ferinzz
@ferinzz 3 күн бұрын
Js teacher i had. "You can still write fast code with js. We even built a server with js that's faster than the one they had before."
@intergalactic6
@intergalactic6 3 күн бұрын
JS on server only makes sense if it’s something like AWS Lambda, it scales and performs very well.
@callowaysutton
@callowaysutton 3 күн бұрын
@@intergalactic6 no.. JS doesn't make sense in v8 isolates either. Systems level languages are the perfect option since you can just pipe the state via stdin/stdout and kill off the instance extremely fast (and efficiently) with no side effects.
@deezydoezeet
@deezydoezeet 3 күн бұрын
What is "bad" code?
@ZT1ST
@ZT1ST 7 сағат бұрын
@4:01; My first thought is that Python allows you to do that. Really, *Java* allows you to do that, though provided that you provide *a* type for the variable - but you could just define it as "Object x", and it'll work just fine.
@ZT1ST
@ZT1ST 7 сағат бұрын
(Also, for C, that's effectively "void", or "void *").
@denissorn
@denissorn 3 күн бұрын
I knew that Java and C# are faster than Go. Btw why is C++ not on the list?
@sealsharp
@sealsharp 3 күн бұрын
The C++ benchmark would be like the C-Benchmark because the measured code does not require any C++ features. It's also not a language benchmark, it's a compiler benchmark. The loops contain a nonsense modulo operation that is just there to not be optimized away and the winning languages are using a compiler (LLVM) that is better at vectorizing the operations. In the related video, Casey shows a slight change to the modulo operation into one that is far faster, so the whole benchmark is "which compiler is good at making good assembly out of a dumb way to do modulo". Zig, Rust, Odin, C, Fortran, Crystal, Swift, all use LLVM. C++ via Clang will not be far off.
@doomon
@doomon 3 күн бұрын
The performance issue of JavaScript compare to the ones caused by my ignorant is wildly negligible.
@Jonjolt
@Jonjolt 2 күн бұрын
Peter Lawrey Needs to be introduced to JavaScript to annoy ThePrimeTime
@szirsp
@szirsp 3 күн бұрын
8:25 Thank you so much! I hate reading comments and "answers" on stack overflow (or reddit or wherever) claiming Premature Optimization is bad/evil. (Instead of helping and answering a simple question.) When someone takes the effort to try to learn something and better themselves this kind of lazy reaction is really unhelpful and discouraging. Sure you don't have to optimize every line of code as you write. BUT if you learn how to write better code once*, then you will write better code for the rest of your life by default! And your un-optimized code will be faster, you don't have to rewrite most of it when it's in a hot spot... It won't be overwhelming to rewrite everything because most of what you have written is just hot garbage... * Of course it's not always that simple, you will need to keep learning, things evolve/change. It't not about learning code lines, but rather learning basic principles and how to apply them! Understanding data structures and the HW (and SW stacks, OS) helps a lot. If you are developing for a specific purpose, platform (embedded for example) then you have to keep in mind the current HW limitations and SW constraints: Using arrays that fit in a cache line vs linked list, different search algorithms, understanding the orders of magnitude differences, memory management, how slow heap allocations are... Learning how modern compilers use RVO, so you can just pass by value a lot more places these days without thinking about it and also getting better performance, then you can update your sense when to still use references... (which can depend on data size, HW memory constraint... If you know / learn / test early on where the crossover points for your platform are then you can make a informed decisions whether things should be passed around by value or reference depending on data and pointer size: 16 bit..64 bit) Sure binary search is fast in large databases, but a simple linear search in a small array that fits into a single cache line will be faster than traversing linked lists. Some of these things don't just effect your code lines, but they can the entire software architecture... which will be harder to rewrite when you have to optimize. But if you know your constraints ahead of time or can make good educated guesses then you can avoid a lot of painful rewrites and optimization later on. The important wisdom skill is to know when an optimization is premature. Learning good habits is not that. If you learn the right way to think about things instead of hard rules, set numbers for when to use what code line then you will be OK for a long time... (Or until WW3, AI, another pandemic or something else destroys us all;)
@thrash1337
@thrash1337 3 күн бұрын
I love JS. As in JSON Statham.
@Digitalgems9000
@Digitalgems9000 11 сағат бұрын
haha yep
@acrosstheocean25
@acrosstheocean25 3 күн бұрын
More article reading content like this please!
@IsaacHisey
@IsaacHisey 3 күн бұрын
Making a JIT Batcher in Bitburner falls prey to a lot of these timing problems.
@knockeddownanotch
@knockeddownanotch 19 сағат бұрын
atlas holds up the heavens while standing on a level earth. earth is flat and motionless man. 🎯
@danser_theplayer01
@danser_theplayer01 Күн бұрын
17:00 it doesn't. Last time I checked it crashed a simple factorial at around 9000 calls.
@robertvandrovec
@robertvandrovec 3 күн бұрын
Devs at V8 are well payed bad guys 😂 JS at servers was a mistake . . .
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
no, v8 is pretty pretty fast. its literally almost the best project out there because many many skilled people are sent to it. what make js bad is bad js programmer writing bad js code and bad js framework. look at just js, its pretty fast using v8
@robertvandrovec
@robertvandrovec 2 күн бұрын
@@superquantumcomputer My point isnt that JS cant be somewhat fast, nor that V8 people arent talented, nor that V8 is a bad project. I made joke that they are villains of the industry for introducing JavaScript to servers. Which i am convinced was a mistake. Its the whole reason TypeScript exists. For servers you want Statically-typed languages that provide MUCH better speed, but mostly they dont consume so much RAM nor they have as variable runtime performance (especially if no GC). In my experience, most of the reasons i heard you would want JavaScript on servers are not really thought thru. Feel free to change my mind tho
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
@@robertvandrovec bru there are tradeoffs and people free to choose, but the advancement of technology should be keep going on, introducing new things and new things. javascript is easier than static typed, to make you get dynamic company profile website faster in the development because it doesnt need to lift high workload right? dynamic company website just return html. then also to get you crud app that manage little data and just be used by a couple admin. then if you want to write online game backends, cloud services, ecommerce backend, real time streaming backend and other that has high work load, then static typed language is the appropiate chooice. so always remember some tools are better at spesific use cases, there are tradeoffs
@hydrobolix3365
@hydrobolix3365 3 күн бұрын
Chrome 2FA Bypass attack?
@krtirtho
@krtirtho 3 күн бұрын
Look at this fool who wanted to tame randomness
@JeremiLorenti
@JeremiLorenti 3 күн бұрын
Please look up Luigi Primo wrestler from Austin TX. I honestly thought it was you Prime. A really cracked out Prime. More than usual. ❤
@SandraWantsCoke
@SandraWantsCoke 2 күн бұрын
Dr. Disrespect is Prime's other role.
@MattDunleavy-t8i
@MattDunleavy-t8i 3 күн бұрын
There couldn't be a more different compiler than JavaScript to C
@nerdycatgamer
@nerdycatgamer 22 сағат бұрын
solution: stop running JS on the server when it was never meant to run anywhere other than in the browser
@Pengeszikra
@Pengeszikra 3 күн бұрын
imho: V8 guys is a good guys!
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
yeah, v8 is pretty pretty fast. its literally almost the best project out there because many many skilled people are sent to it. what make js bad is bad js programmer writing bad js code and bad js framework. look at just js, its pretty fast using v8
@cbbcbb6803
@cbbcbb6803 Күн бұрын
Can JavaScript just be rewritten from the ground up. Call it JavaScript++ or JavaScript# or JavaScript! Or something.
@superquantumcomputer
@superquantumcomputer Күн бұрын
lmao for what? javascript is ment to program frontend then be consumed by browser engine in secure way
@Digitalgems9000
@Digitalgems9000 11 сағат бұрын
LOOL
@nuvotion-live
@nuvotion-live 3 күн бұрын
Help me uninstall JavaScript from my computer
@XDarkGreyX
@XDarkGreyX 3 күн бұрын
Wild node.js process appears
@dev.j255
@dev.j255 Күн бұрын
A classic, rust devs being jealous of the popular kid that everyone loves
@superquantumcomputer
@superquantumcomputer Күн бұрын
said from a kid. why would a king jealous of a mini servant
@mattymattffs
@mattymattffs Күн бұрын
If your benchmarking JavaScript then you're using the wrong language
@kunai9809
@kunai9809 3 күн бұрын
Yavascript
@eduardofernandez2697
@eduardofernandez2697 4 күн бұрын
Asteroid be like: I'm about to hit earth Prime: Javascript benchmarking sucks
@tedchirvasiu
@tedchirvasiu 3 күн бұрын
8:37 - W
3 күн бұрын
Dash oh jeez!!
@eduardflorea9823
@eduardflorea9823 3 күн бұрын
Isn't this nonsense the reason Web Assembly was created.... so we don't have to even try and benchmark JS.....
@HhddGufif
@HhddGufif 3 күн бұрын
So how do you quantify possible performance gain. By benchmarking
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
wrong, webassembly was created to enhance what you can do in client, not to replace js
@phoneywheeze
@phoneywheeze 2 күн бұрын
browsers still don't run wa so it's still compiled to js
@superquantumcomputer
@superquantumcomputer 2 күн бұрын
@@phoneywheeze this is wrong, web assembly isnt compiled to js. its a binary format just like assembly then will compiled to machine code once on the fly ( the detail of v8 version in their blog "web assembly compilation pipeline") then be executed directly, doesnt need to be interpreted, it run directly on web assembly runtime that in the engine (v8, jsc, etc has web assembly runtime inside them). but it will need to call js code in order to manipulate dom object, because only js has the access to dom object. they dont expose dom direct access to web assembly because of security, it will need all the engine to make sure every dom api call by web assembly are secure and doesnt has vurnurabilities, they have the experience that maintaining security in the js one is already hard, then in web assembly one you should be able to imagine how hard it will be, plus calling dom api via javascript is very fast and way very cheap, its not the calling via javascript that slow, but the dom itself is the one that slow, dom is very complex data structure, its the dom itself that slow, its why they dont work in making web assembly has direct access to dom api because the benefit isnt worth the trouble
@HhddGufif
@HhddGufif 2 күн бұрын
@@phoneywheeze so I don't think that's true. Or even logical
@jamesc2810
@jamesc2810 3 күн бұрын
hi KZbin.
@Free_kitty0
@Free_kitty0 4 күн бұрын
Hi!
@trueberryless
@trueberryless 3 күн бұрын
Zoom
@DaPaBe1999
@DaPaBe1999 4 күн бұрын
I dont get why ppl hate js because of the implicit behaviour, any sane application doesnt require obscure implicit behaviour at most just coercion
@EnDeRBeaT
@EnDeRBeaT 4 күн бұрын
the point of obscure implicit behaviors is that nobody needs them, they appear out of nowhere
@XDarkGreyX
@XDarkGreyX 3 күн бұрын
I should have gone to uni
@abrarrauf3801
@abrarrauf3801 4 күн бұрын
Third comment!
Every programming language explained in 15 minutes | Prime Reacts
43:42
How Honey Got Away With It
25:40
Theo Rants
Рет қаралды 121 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
"We Ran Out Of Columns" - The Worst Codebase Ever
23:29
ThePrimeTime
Рет қаралды 654 М.
I Can’t Stop you from Buying Amazon’s New TV… but I’ll Try Anyway
23:50
Why Your Backend Shouldn't Serve Files
19:40
Boot dev
Рет қаралды 60 М.
Why Don’t Railroads Need Expansion Joints?
27:20
Veritasium
Рет қаралды 3,1 МЛН
Quantum Hype Goes Crazy. But Why?
9:30
Sabine Hossenfelder
Рет қаралды 40 М.
They patched the game because of ME...
27:36
Real Civil Engineer
Рет қаралды 631 М.
The Honey Scam: Explained
10:53
Marques Brownlee
Рет қаралды 4,5 МЛН
Why I Prefer Exceptions To Errors
1:05:31
ThePrimeTime
Рет қаралды 194 М.