Rust keeps making JavaScript faster
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2024
- Delve into one of the most prominent trends within the JavaScript ecosystem. Join me as I unravel how Rust is revolutionizing JavaScript performance in today's video.
Free Rust cheat sheet: letsgetrusty.com/cheatsheet - วิทยาศาสตร์และเทคโนโลยี
📝Get your *FREE Rust cheat sheet* :
letsgetrusty.com/cheatsheet
nx > turbo anyday ...
Fun fact: NaN is a number in every programming language that uses floats, which is pretty much every single one of them. That's because it's defined by the IEEE754 standard
Hmm this fact doesn't seem to fit my narrative
Ever since fpus became ubiquitous then the languages use whatever the fpu uses. Which isn't always IEEE, but usually similar and generally includes NaN
To be more precise, NaN really represents a particular value of a numeric type (namely those following IEEE 754), but this value is not a number by itself, hence the name NaN.
You're mostly right, but there's a slight clarification to make about NaN. While NaN stands for "Not a Number," it's not actually a number itself. It's a special value in floating-point arithmetic that represents an undefined or unrepresentable result.
The IEEE 754 standard, as you mentioned, defines how floating-point numbers are represented and manipulated in computers. This standard includes NaN as a way to handle operations that would otherwise result in undefined values, like dividing by zero or taking the square root of a negative number.
So, while every programming language that uses floats has NaN, it's not a true number but rather a placeholder for indeterminate values. It's an important part of ensuring robust and predictable behavior in floating-point calculations.
Here are some additional interesting facts about NaN:
There are actually different types of NaNs, such as quiet NaNs and signaling NaNs, which serve different purposes.
NaN is not equal to itself, even though it might seem counterintuitive. This is because NaN represents an undefined value, and two undefined values cannot be compared meaningfully.
Many programming languages provide functions to check if a value is NaN, which is helpful for handling potential errors in calculations.
I hope this clarifies the concept of NaN!
@@letsgetrusty XD justs today i learn that in collage
It would be interesting to see you building a beginner friendly website project using rust.
That's an oxymoron
good one
Thanks for the suggestion :)
@@codejunki567 In my experience, Rust and JS difficulty even out. JS might be initially easy, but all the bloat, tooling concepts and things that evolved over time and got deprecated is quite crazy. Rust on the other hand is hard to learn from the start, but after you overcome the beginning hurdle, its as easy as python and nothing will surprise you down the line.
@@idedary Well what you just compared isn't a beginner friendly JS program so idk about your comparison still.
NaN being a Number is not the fault of JS but due to the floating point standard. This is also the case in rust.
Yeah, I've given JS enough guff about its many eccentricities and foibles, but I really do wish people would stop harping on JS about that one. It's just the IEEE spec from what I understand. Now their lack of a real integer type is fair game IMO.
The issue with JS is that it has only 1 number type, and which is actually just 64bit floating point, and this causes lots of issues, such as with precision.
Just consider things like 9999999999999999 and 0.1 plus 0.2, which show clear rounding errors when evaluated. This is a real limitation.
I am not a TypeScript developer, but since it just compiles to JS, I believe it cannot even have solved that problem. And some people say that JS is better than TS anyways. I can understand that, when it's not a real type system but a simulated one.
@@jongeduard Wanting a simple type for 64 bit ints is fair. But, 0.1+0.2 and other precision issues with non-integers is not an issue with JS only having a single number type, it's IEEE754.
@@jongeduardyou could do fixed point arithmetic in js
Thanks for clarifying :)
What I don't understand is, why they get surprised by the performance when they should be questioning how slow the others are?
That's the real question
What do you mean by others.. they have compared these selves with their older JavaScript version..
I don't know what you mean by others
Because they should not be in the industry.
@@Mr.BinarySniper yes I mean the js versions ofc
You can make JS tooling faster by optimizing it. Maintainers are either burned out or working on other stuff and it isn’t a priority
NaN being a number is from IEEE 754. Rust adheres to this with floats as well
Not a number.
Yes but Rust even has 128 integer numbers, both a signed and an unsigned version. Not many languages have that. I am quite happy.
JS has only floating point numbers, that's the problem.
It is literally only using the floating point unit your CPU and nothing else. This is really strange when you need to work with indexes into arrays. Rounding errors and not a number values do not really add up.
@@jongeduard JS uses integer types under the hood with JIT optimization.
@@pepkin88 I know, but it does not make a difference in all aspects, it is an implementation detail of the V8 runtime. It matters for performance, partially.
It does this for the smaller integer numbers where difference between integers and floats is impossible to notice, but for higher numbers where FP values loose precision, it cannot keep integers.
The burden of JS is that it needs to maintain compatibility with everything on the web, at least as long as it does not introduce actual declared types but relies on the current loosely typed variables only.
Declaration with a new syntax should be able to fix that I believe. But no one wants that and too many people believe that TypeScript is the better option apparently.
It would be nice to do another video about Rust being used more and more in the Python community - with tools like Polars, Ruff, Robyn etc getting more and more traction.
Not a number is a number. That's from the floating point spec. That's not JS fault.
Beat me to it. Out of the 999 weird behaviors JS has, that one is not JS specific, and, as you've said, it comes down to the binary level of how floating numbers are interpreted.
Moreover, not only is it "not JS fault", it would be highly impractical if it was not considered a number
@@carlosmspk I have always found that NaN === NaN is false to be an odd one. I have never dug into it as to the "why". Maybe I'll do that right now.
Edit: According to the standard, NaN is considered unordered, so it is not equal to, less than, or greater than anything, including itself.
Yep, that's where I stopped watching the video. Clearly they don't know what they're talking about. Also they called NaN a type!?
From a readability standpoint, it's busted af.
It is the fault of js. The type is number. Not float
Tauri is good, especially for people who like/use Javascript a lot. I'm not one of them though. So if a comparable cross-platform and stable Rust GUI appears, I'll switch to that. So far it seems like Tauri is the best one for user/developer experience, other GUI libraries are either still in development or have quirks preventing from their serious adoption.
You can use tauri with almost only rust in front end and backend. It works with yew for example for fronted. It's still not the same as native rust gui (you have separation of fe/be).
Worth looking into gtk rust library- not stable yet however.
@forthphoto Tauri/Yew stack doesn't seem to be officially supported, and you still need Javascript glue, as far as I know. When something more convenient comes up, I'll definitely use that
@@yds6268 take a look at dioxus. it is based on webview and there's no javascript glue for desktop apps. also, the tauri cli officially supports leptos, sycamore, yew and one other that i can't remember at that moment.
What do you think of Slint, which reached 1.0 last year, and Iced, which System76 is using for the Cosmic desktop?
@@yds6268yes because at the end of the day, the browser only supports JS. The benefit over using WebView vs native, is the speed in which you can iterate the front end. With the ever increasing cross-platform standards, it's a huge no brainer.
I have been loving writing native rust addons for js using NAPI-RS, regularly getting over 1000x speeds over orginal Node code.
So basically it has nothing to do with Rust itself but with going from interpreted languages to compiled/native languages. Same performance could be gotten with eg C++, but somehow the JS ecosystem all these years ignored native language implementation. For whatever reason, they took interest now and decided to use Rust as the new kid on the block.
WAAAAA THEY WONT USE MY FAVORITE template LANGUAGE
@@patrickkkkkkkkkkkk You missed my point. I wonder why the JS world didn't use native/compiled languages for their tooling already? Why the hell did they wait for something like Rust to do it?
@@sledgex9 because writing tools in c++ is a pain in the ass. It's alot easier to tell someone to just "cargo new project" instead of configuring their own makefile or Cmake file that has so many quirks. i dont even think it's a matter of language spec itself, just the fact that the tooling and usability is much easier.
@@sledgex9 The used it with gyp. And gyp sucks a lot.
Then came esbuild and said - you don't need gyp, you can just distribute precompiled binaries. And suddenly everyone is writing native N-API code
@@axisaligned9799 You too missed the point. The question is not about C++ specifically (arguably, it's overkill for webdev), but native/compiled languages in general. They were ignored by web developers for so many years, even though everyone told them how much performance they could gain, and now they've suddenly discovered Rust and look so surprised that it works so well for them!
There is also STC which is still in development but will speedup type checking for typescript
Hey Bogdan, I can't thank you enough for the knowledge you've shared on "Let's Get Rusty"! 🙏 Your Rust tutorials have not only helped me build my own library for matrix manipulation, but they've also inspired me to start my own TH-cam channel. 🎉
On my channel, I'm sharing my journey as I code along and apply what I've learned from your tutorials. It's been an incredible way to reinforce my understanding and share my progress with others. Your work has truly sparked a passion in me for learning and teaching Rust.
Keep up the fantastic work, you're making a huge difference in the programming community! 👏👏👏
It would be great to see a new video from you about rust-tools-ecosystem incorporation into existing front-end project and how it helps to increase performance.
.. could care less if my project builds 10sec or 1min ,
my teapot is boiling for 5min
Rust compilation time isn’t even its strongest point
Yeah, Go is like "you think that's fast ? "
Lol many rustaceans actually complains about the compilation times.
@@lgasc only after using go though
@@lgasc which confuses me continuously cause it seems extremely fast to me.
i heard that they are experimenting with multi-threading to improve rust compilation times. hopes that goes well.
Can you check that NaN is a number in the Chi Shi?
Prisma js is an ORM that uses a rust SQL engine, though it heavily affects cold-starts with long compile times. Rust major advantage is having no garbage collection, and relying on the compiler and the dev for safety.
Which Shopify build tool runs for one hour?
@letsgetrusty I want to know what's best tool in rust to run already coded nodejs application?
More videos for Rust supporting JS please!
You are my WebDevSimplified of rust
WDS is LGR of JS
Great videos mate.
What are your thoughts on Actix web for building backend of websites?
In my opinion, Axum is better
Use Axum instead
What is "oxidation"? Does it have to do with Oxlint?
Oxidation causes Rust, there for introducing oxidation to ESLint -> Oxlint. That's pretty much the "inside joke" he's using here.
This is also happening in the python ecosystem with ruff
Code with Antonio made a cameo!
Can you do a vid on using Javascript with Rust? Especially WASM?
There is an online Rust-WASM book on the official site. But no harm in having videos as well.
You know that Rust's NaNs are also of numeric type (f64, f32), right?
And what about WebAssembly modules written in Rust that can be executed by JavaScript applications ? :)
Interesting. The same movement is happening on python world
great topic 👍
But what about "Biome". Prettier's javascript counterpart
Was node ever written in JS? I can't think how is that possible.
C++ actually, but I do agree with the last sentence however.
Love the video. I would rather be the contributor than the user of new framework.
As beginner I wonder, things like these were never done with c or c++.
therefore, it is unsafe and has problems with working with memory
Js infrastructure isn't even all of it. With Rust and Webassembly Rust is also taking over performance critical sections of code.
I don’t think webassembly fast enough for using performance critical piece of codes. I have tested Mandelbrot algorithm in rust and compiled as wasm in release mode but JavaScript was faster 2x than its wasm version. It is useful if there are libraries written in rust and c++ like physics engine otherwise I don’t think it is fast
@@kamildoan yes wasm isn't always faster ... yet. If js can use webgl or webgpu it would be faster than cpu bound wasm. However wasm is still new as compared to js. All other things being equal static typing is always faster as you can optimize more code paths. So as wasm matures it should be more consistently faster at cpu bound tasks. I'm learning wasm now so I'm betting on it
@@kamildoanIt's taken a lot of effort over a long time to get JS as fast as it is
WASM will get faster. It's just a matter of time
@@kamildoan thats actually dependant on the WASM runtime you use. If you want a promising new runtime try the wasmer engine and run the wasm file with LLVM jit compilation. Ive tested rust code that was only 2x slower in wasm vs running it natively...
Why is there no "rewrite with C++" era?
Or you could ask, back in the day, why didn’t they write the tools in C/C++ to start with?
@@kevinmcfarlane2752Isn't part of Node JS written in C++?
@@kevinmcfarlane2752 js is much more comfortable to write in than cpp. but how much is the difference between cpp and rust?
@@zoey5104 yes and this couldn't be done in JavaScript since it used lower level apis
Didnt know that ESLint had so much more potential in terms of performance. Probably made some mistakes along the way in terms of designing that linter
Bogdan looking sexier every day!
Just a side note: Vite is pronounced as in French, with a soft "i".
In Rust (1.76), `println!("{}", std::any::type_name_of_val(&f64::NAN));` prints `f64`. Is it bad for Rust?
If not, why `console.log(NaN)` printing `Number` is bad for Javascript?
You can try, in Rust, the expression `let v = 0./0.;` gives a `NaN` value to `v`. But `v == f64::NAN` (or `v.eq(f64::NAN)`) evaluates to `false`, like any other language (most of them?), including JS (in JS, `0/0` value is `NaN`, but `0/0 == NaN` evaluates to `false`).
Yay another Lets Get Rusty. :)
Bun already did this to make it faster and address this issue
No one:
Rewrite in Rust: YES!!!
It obvious that anything that compiles to native binary code will outperform javascript (written in rust or for instance in C,C++, D, Go, Zip, Swift, etc) I dont see the advantage of rust here. Perhaps the best option would be to have a typescript to native compiler, and I saw a project for this based on llvm. Then you could migrate your typescript code base to something that runs at native code speed!
Non-GC memory safety and security would be the advantages over the others.
Idk with you guys got it but This video was entirely made by ai, voice and video.
Nice video btw
Rusr is like cpp if the compiler was a total Karen
VSCODE should be written in Rust
As a React dev, Oxlint & Turbopack is ❤
Damn, on the other hand, they'll perhaps crap the rust just like they did to everything that touched web
i don't think so, rust is a very "opinionated" language, so it won't be that susceptible to taint
@@jolynele2587 I hope so, but what you can do when much of the community becomes money seeking reckless web devs
@@Beryesa. The worst ones will be bullied away by the borrow checker
What about zig
It’s not mature yet. Not reached 1.0. From the little I know though there might be room in the future for both Rust and Zig.
Public class javaTools extends JFrame(
If you look the rust issues there is no difference in buggy.
I honestly love how unapologetic you are about your Rust advocacy. No fluffy qualifiers to appease people who hate Rust.
Not saying it's bad to add a bunch of fluffy qualifiers -- but we don't all need to be ambassadors of "everything is equal, actually".
I don’t mind people loving Rust, so long as they don’t say everything else sucks and must be shunned and we should rewrite EVERYTHING in Rust.
Build times went down from over an hour to mere seconds… doubt... (¬_¬)
Linting times. Have you ever used eslint?
Just yesterday I accidentally tried to lint a logs file (~300K lines of json) with both eslint and oxlint.
ESLint failed with out-of-memory after 30 seconds, oxlint finished in 2 ms.
Javascript and React needs to be replaced. Long live Rust
Awesome!! Finally it is not Javascript... it is Javas-cRust!! :)
Дякую, Богдане! це корисно
Javascript is like a virus, it started as web frontend now we have it everywhere
So many tools to work with json.... i was looking how to decoupled a drupal site.... so many tools like nextjs... so after you have a ready tools to do lot of js everywhere....😅
I love rust and javascript❤, I really want the benchmark of new rust based tools for javascript
nextstep: fully replace javasscript with rust
Broo !! Going from 45 minutes to 10 seconds is unbelievable
I know oxlint is great , but it can be that eslint is bad, no ?
They're replace the NaN language with the language of thousand string types 💀💀
make a video
Vercel is not the creator of web pack
You know NaN exists in any language that supports IEEE floats, right?
He created Deno mainly because of its decentralized nature... by using the centralized cargo.. lol
After knowing Rust is named after the rust fungus, oxidation jokes don't work well anymore.
Still works as a pun
1. Learn rust tools to improve JS.
2. Learn rust to build the tools to improve JS.
3... Wait... Rust can WASM... Why not just WASM?
Rust is awesome and all. But its kinda very very verbose... Its hard to write.. like for a friggin user input .. we need to literally write a 4 line code
Ridiculous. My "builds" take 0 seconds. Because JS doesn't require builds.
"The event from 2010." that enabled the use of JavaScript on the backend side, marks the downfall of the entire JavaScript ecosystem... Pandora's box was opened, never to be closed again.
There's a nice saying, I paraphrase: "Whenever you write Node.js code, you're effectively making a rollercoaster in Excel" - Primeagen.
JavaScript is a language that deserves a hall of fame, but it's time for something new, as the number of inconsistencies and flaws in it is too great.
From a language for manipulating the DOM to a language in which server code is written. I think it's wise to know when to stop with something.
Rust tooling and the acceleration it brings is cool, but it's futile.
You missed jquery !
"with a type called not a number that is actually a number" - and that is where I stopped watching the video because you identified yourself as knowing nothing. Look up IEEE 754 floating point arithmetic. These days pretty much all languages use IEEE floats (I think the exception are some shader languages) and that comes with NaN. Its IEEE that says that floating point _numbers_ have NaN values and that NaN != NaN etc. JavaScript has a lot of shortcomings, it's floating point arithmetic is not one of them.
PS: NaN is not a type. Its a value.
It was also exactly when I downvoted. I’ll mark the channel as “ignore” from now on.
I just clicked on this video, and I'm already sad. I don't want javascript to be slow. I don't want it to be fast. In fact I don't want it. (Btw my main language)
I still prefer C++, but Rust is much better than all this web crappy tools. I hope web gets rusty, for its own good.
node was a big mistake
How so? It has shortcomings, but I've always seen it as a win.
@@SRG-Learn-Code..I agree with you, but one mistake I do see in the industry is people thinking that NodeJS is the best tool for the BE _simply_ because it will mean the BE and FE use the "same" language--that's always the justification for a NodeJS/Express server--and I don't think it's a good one.
Meh, none of the rust tools may change the fact that JS is shit. Only rust WASM will save us, or Elm/PS
99% of the comments here: "Did you KnOW ThAT NaN exists in any language that supports IEEE floats?!?!?"
Rust isn't fast, JavaScript et al. are just slow.
How can you make javascript faster?
By removing javascript 😂
Well said 🤣
Node.js was one of the biggest mistakes ever
Sorry but I consider Deno as a failure...
“multiply a string and get a number” that’s literally not what happens lol
I know that’s probably a bait that i’m falling to but quite annoying these “oh javascript is so bad, look how this behaves” stuff, lol
that’s literally the stupidest trend from tech “influencers”
Like my comment if you want to see rust projects
Help me to continue, please:
typeof(NaN) === 'number'
typeof(null) === 'object'
'4' * 2 === 8 && '4' + 2 === '42'
null == undefined && null !== undefined
{}.unexistent === undefined
42..toString() === '42'
NaN !== NaN
{} - [] === 0
([] - {}).toString() === 'NaN'
[2, 4] + [2, 4] === 2,42,4
null >= 0 && !(null > 0) && null != 0
Number.MAX_VALUE + 1 === Number.MAX_VALUE
Some of "problem" is not entirely js problem
1. `NaN !== NaN` is standard specification of NaN in IEEE, it's literally how to check if it's NaN or not for most language
2. `Number.MAX_VALUE + 1 === Number.MAX_VALUE` is precision error for float, happened on every language
3. 42..toString() === '42' is tricky but understandable, since `42.` is counted number token, but generally better than wrapping in wrapper class to invoke method like java counterpart.
But yeah most of it are still too bs lmao
@OnFireByte Thank you, but where did you find the word "problem"?
Also your second point comes from IEEE 754 as well, but having a spec doesn't make these things any less fun)
And brainfu"n"k is also understandable, but it doesn't make it nice to work with.
I'm just having fun and wondering what other interesting nuances can be in the list 😉
The more you hate it, the more it will flourish 😂
It will probably stays long after yoy guys who hates it died 😅
Javascript always sucked, always will. Don't try to portrait it as a survivor between infirior technollogies
can we please just finally end JS completely? bloat needs to end
Rust is like a big downgrade from C++
Dude, you such a Rust fanboy, completly forgeting that Bun is writen in Zig and its so so much better and faster than Node.
It's a Rust channel...
@@yunusycle97 if this is a fanboy rust chanel them im out, i was hoping that this is not the case and the OP is more open minded
JavaScript managed to basically cause irreparable harm to the tech industry as a whole. With WebAssembly, Rust can potentially be the savior. Sadly Rust is a shitty language as it's all functional garbage, but it's a million times better than C++, and more efficient than trying to AOT-compile Java or C# or some other managed language.
["Sadly Rust is a shitty language as it's all functional garbage"]
I doubt you can reasonably justify this statement, because you also probably do not even know what "functional" means and surely don't know what Rust is.
Before any fellow Rust fanboys try to address this person: if you click on their profile you'll see the "comments on other videos" section filled with "rust is dumb", "should have used traits", "rust isn't hard, it's just a dumb bullshit language" etc. Doesn't seem very interested in Rust, unfortunately.
While I think this could be due to bad teaching, I'd reconsider typing out a full "no it's not!!!1!1!" comment if the person you're writing it for isn't going to agree anyways.
That said... I'll take the bait! 😂
- Traits: you could just view them as interfaces from Java/C# if you like? And then when you want, you can learn about the depths of it but at a high level that's what they are...
- Rust itself being "not hard, just dumb": Are you entirely sure that "dumb" is the right word to describe the language that's popularizing the borrow checker, solving entire classes of bugs in the process? Sure, I hate some parts of it too: string types, verbosity, `unsafe` contamination, the list goes on... but personally, opening Rust for the first time isn't actually too hard, tbh. Just a different way of thinking, the same way I felt when I first learned Python and felt dynamic typing being weird. I figure Rust gets seriously hard later on, but we'll see. Why do you feel Rust is dumb?
- Rust being "functional garbage": Okay, I can honestly understand the sentiment of "Imperative C did everything just fine, we didn't need to make any languages past the year 2010". I am also aware that functional programming can be FAR from usual for... well, everyone. But... dumb? Isolating side effects was previously a good practice, and is now a language requirement. That's all I see it as, more or less. (Please nobody tell me what a monoid in the category of endofunctors is)
And JS causing irreparable harm to tech... is that re.: the framework shenanigans these days? Poor error handling, "11"== 11 type problems? From a historical lens, I think it's done good things but I haven't worked much with it 😅
Kind of confused: first, you seem like a Rust fanboy; then, you call it a shitty language, but then state that it's far better than 99.99% of the languages we use. Are you some kind of C mad lad or assembly lunatic?
JavaScript Rust