HN Theater @HNTheaterMonth

The best talks and videos of Hacker News.

Hacker News Comments on
How Slow is JavaScript Really? JavaScript vs C++ (Data Structures & Optimization)

SimonDev · Youtube · 6 HN points · 0 HN comments
HN Theater has aggregated all Hacker News stories and comments that mention SimonDev's video "How Slow is JavaScript Really? JavaScript vs C++ (Data Structures & Optimization)".
Youtube Summary
Is JavaScript really that slow? Or is that just a leftover impression from the old days?

Patreon: https://www.patreon.com/simondevyt

Follow me on:
Twitter: https://twitter.com/iced_coffee_dev
Instagram: https://www.instagram.com/beer_and_code/
Github: https://github.com/simondevyoutube/

In this video we talk a bit about JavaScript vs C++, and the performance difference between them. We'll talk quickly about the history of JavaScript before working through a few small benchmarks to compare performance between them, using various optimization levels for gcc. It's kind of interesting to see how much JavaScript's performance has evolved with JIT (just in time) compilation since the early Netscape days. The v8 team has made enormous strides in performance and is narrowing the gap with C++ year by year. We'll also walk through some examples of what you can do with your basic C++ code to squeeze more performance out, either by using better compiler flags or SSE/AVX intrinsics to get better usage out of your CPU.

What's covered:
* Super brief history of JavaScript and V8
* Benchmarks and comparison of JavaScript vs C++
* SSE and AVX intrinsics
* gcc -Ofast and float associativity
* Some closing thoughts on JavaScript's performance today, as well as C++.


Speed, Speed, Speed: JavaScript vs C++ vs WebAssembly:
https://www.youtube.com/watch?v=aC_QLLilwso

Godbolt:
https://godbolt.org/

Wikipedia:
https://en.wikipedia.org/wiki/JavaScript
https://en.wikipedia.org/wiki/Associative_property

Various blog posts from V8 team:
https://blog.chromium.org/2010/12/new-crankshaft-for-v8.html
https://v8.dev/blog/10-years
https://v8.dev/blog/launching-ignition-and-turbofan
https://v8.dev/blog/adaptor-frame
https://v8.dev/blog/high-performance-cpp-gc
https://v8.dev/blog/fast-super
https://v8.dev/blog/preparser
https://v8.dev/blog/spread-elements
https://v8.dev/blog/background-compilation
https://v8.dev/blog/fast-properties
https://v8.dev/blog/fast-for-in
HN Theater Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this video.
Apr 21, 2021 · 3 points, 1 comments · submitted by scanny
dheera
I felt really stupid when I wrote this yesterday, which you would NEVER do in C++:

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status === "fulfilled") {
                ....
            }
        }
    }
Like really? We want the processor to test for equality 9 times for "f", "u", "l", "f", "i", "l", "l", "e", "d"? Or is there some built-in optimization for this?

Or should I do this, which feels hacky, but reduces it to 1 equality test?

    const FULFILLED === "f";

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status[0] === FULFILLED) {
                ....
            }
        }
    }
Apr 20, 2021 · 3 points, 0 comments · submitted by onion2k
londons_explore
Now do the same again, but instead of just implementing your algorithm directly, use a few hundred npm packages to achieve the same. Don't forget to convert to/from base64 a bunch, and obviously make sure the famous leftPad is involved every step of the way.

For fairness you can use a heavy sprinkling of inappropriate boost in the C++ side.

Now how do things compare?

HN Theater is an independent project and is not operated by Y Combinator or any of the video hosting platforms linked to on this site.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.