Тёмный

Can Rust save the Planet? A Clickbait look at energy efficiency of Rust vs Node 

Michael Mullin
Подписаться 2,8 тыс.
Просмотров 2,2 тыс.
50% 1

Rust is claimed to be more efficient than other programming languages, and thus should have less Carbon footprint than other programming languages. But I've never seen hard data to support this argument.
So I did the work myself to see if this is true? How much less carbon would be emitted if we, computer programmers, switched from Node applications to Rust?
NOTE: For Clarification, I don't mean that I don't like other tech youtubers. I love guys like Vagelis or Chris Hay. I mean a lot of youtube is silly pranking videos, or hate vendors, or talk-show clips, or celebrity culture things. We need more weekend hobbyists who are learning stuff and sharing what they learn.
US EPA Greenhouse Gas Calculator: www.epa.gov/en...
Skip to the Code @: 22m25s
Thumbnail from Michael Benz: unsplash.com/p...

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 23   
@wezm
@wezm 2 года назад
Interesting research. Timestamps in case they are useful to others: 0:53 Agenda 2:14 Self Promo 4:56 Problem Statement 7:04 Hypothesis 7:58 Experimentation Parameters 10:48 Algorithms Tested 15:40 Problems with Experiment 22:17 Code & Results 27:58 Test 1 39:50 Test 2 53:11 Test 3 59:12 Bun JS?
@masmullin
@masmullin 2 года назад
Thank you for the timestamps
@wezm
@wezm 2 года назад
@@masmullin No worries, if any are off let me know and I can tweak them.
@ariseyhun2085
@ariseyhun2085 2 года назад
Why not put this in the descripion instead, so RU-vid will add the timestamp sections to the video itself
@alexandersemionov5790
@alexandersemionov5790 2 года назад
Good job. And good timing during energy crisis. I ENJOY this type of long format as more details and thoughts are revealed. Keep it up 👍
@Vagelis_Prokopiou
@Vagelis_Prokopiou 2 года назад
Excellent video and a good starting point for such an initiative. Thanx Michael.
@pranav.bhasin
@pranav.bhasin 2 года назад
Michael, I've been watching your long-form content and I've enjoyed how thorough your work has been. I feel like you'd gain a lot more traction if you could cut the video into "focused" clips as well. (similar to how streamers take stream clips and create RU-vid videos).
@Andrew-jh2bn
@Andrew-jh2bn 2 года назад
I think every time you say "axiom" you mean to say "axum"
@snapstromegon
@snapstromegon 2 года назад
While this is impressive - especially how close JS gets - I would probably change some things in the JS code: 1. Use fastify instead of express, since it's more modern and faster 2. Don't make the handler functions for the express routes async functions as they are not calling async internally and this will create some overhead 3. While I did not do performance tests, I would use the normal JS array (which already has deque capabillities) over the library one, since at a first glance it seems to me like that does a lot of unused overhead stuff. 4. The "correct" way of doing multitasking in nodejs is to use the "cluster" module or even better "workers". But this shouldn't make a big difference IMO. 5. I wonder why in your tests sync file interactions are faster than async (my guess is, because it's in memory), but I would've expectet parallel file stat requests with Promise.all to be faster. Of course it's easy to write these things when I haven't really done any testing and just watched the great work of yours. I definitely agree that bun isn't ready yet, but I would've loved to see a comparison with deno instead, as that is a widely adopted alternative to node.
@masmullin
@masmullin 2 года назад
I've followed your advice for the JS and have seen significant performance boost (nearly 20% improvement) on the users test. Will update with a follow up video in the next few days
@simonyin9229
@simonyin9229 2 года назад
Thank you for putting in the hard work. I hope this gains some traction.
@defnlife1683
@defnlife1683 10 месяцев назад
inb4 it causes more damage due to the Jevons Paradox. (this is very awesome btw)
@codeecubix
@codeecubix Год назад
I was hoping you'll test RUST vs PHP
@masmullin
@masmullin Год назад
Check out Vagelis channel ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Vk41-xPxQI4.html Tl;dr php isn't in the same league
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 2 года назад
Regarding the json request: When doing the Rust example, you could skip creating a user and avoid a few allocations, would perhaps speed it up even more
@masmullin
@masmullin 2 года назад
Not sure how to get json out of the sqlx rows other than handcrafting, or using serde_json on a user struct. hand crafting is not only worse code (more error prone), but also slower. That said, there are a few simple tweaks (instead of .collect(), pre-allocate the result vector, use row.get() instead of row.try_get) that can improve performance by 1% for the same 76.5W. Not enough to make me want to redo the video nor change my conclusion. There are more invasive performance boosts which can be done to the rust code (see previous video for possible techniques), but this handicaps the experiment as I am sure there are similar techniques to apply to javascript code which I am simply too novice in the language to apply. Optimizing Rust via: - mimalloc - thread_local! - single allocation the Json Buffer - use smallstr::SmallString instead of String for first_name and last_name Yields: 1692req/s (1.15x more req/s) with an energy usage of 74W for a milliwatt/req value of 43.7. CO2/Kg/Yearly = 1657.59 (down from 1972.37). Thus the usage of unoptimized node vs optimized Rust is 1.31x more CO2 emitted for the theoretical case of 10000 req/s requirement. So yeah, Rust can be further optimized. However, this is now comparing highly optimized rust code by an experienced Rust developer vs non-optimized node code written by an extremely junior developer.
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 2 года назад
@@masmullin "hand crafting is not only worse code (more error prone), but also slower." Why? directly writing the JSON String could avoid up to 2 allocations per user, which should improve it massively (well, if you don't use small string allocations already)
@tomwilliam7299
@tomwilliam7299 Год назад
Thank you 🥰🥰🥰
@masmullin
@masmullin Год назад
You’re welcome 😊
@user-zq8bt6hv9k
@user-zq8bt6hv9k 2 года назад
Yeah I agree with u about RU-vid content sucking. Unfortunately, if that works, it's because there is an audience. Like your content, hope u continue even though you might not make the same amount of views than "top 5 programming languages you must learn in 2022 according to google trends"… I think the 75 dollars worth it, gg
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 2 года назад
why is the maximum for Rust and Node 1580? Feels a bit odd - is it an OS limitation?
@masmullin
@masmullin 2 года назад
I misspoke when I was explaining my network speeds, I said "gigabyte" when I meant gigabit. Thus the 1580 is very close to the maximum transfer available on my network.
@climatechangedoesntbargain9140
@climatechangedoesntbargain9140 2 года назад
Lol using pound and kilogram in one sentence :D Americans 😃
Далее
Lets Review some Code
1:38:44
Просмотров 903
Pure Comedy #ti13
00:38
Просмотров 213 тыс.
AI can't cross this line and we don't know why.
24:07
Просмотров 326 тыс.
Higher-Order Components Are Misunderstood In React
17:38
Rust Allocators and Memory Management
43:51
Просмотров 9 тыс.
Let's Fix The Fatal Flaw in TypeScript's Union Types!
13:45
Rust: The Dangers of Early Performance Optimization
36:22
Plug WASM into Rust with wit-bindgen
35:15
Просмотров 2,9 тыс.
So You Think You Know Git - FOSDEM 2024
47:00
Просмотров 1,1 млн
Rust Password Hashing: Cracking the Shadows
37:30
Просмотров 1,5 тыс.