How Slow Is JavaScript? | Prime Reacts

preview_player
Показать описание
Recorded live on twitch, GET IN

MY MAIN YT CHANNEL: Has well edited engineering videos

Discord
Рекомендации по теме
Комментарии
Автор

in case anyone is interested more about game development and how to avoid garbage collection: look at "object pooling". You basically have pools of specific objects that you create/"destroy" a lot but instead of removing them and let the GC remove them, you put them into a pool to reuse them later on. When creating a new object you instead check your pool first, if there is a free instance available and if yes, you use it. Otherwise, you create a new instance that will be later on added to the pool when no longer needed.

That way GC doesn't kick in but of course you require more memory over time. Just a quick and simple explanation, there is of course more to it.

Just wanted to share that with you lads if anyone is interested.

Quillraven
Автор

Saw this recommended and got nervous sweats heh. Very cool to get covered here!

simondev
Автор

TypedArrays are fun to mess around with until you realize that nobody uses them and you slowly go insane rewriting every library in binary to get a performance boost. Don’t look at web sockets. UDP isn’t possible and most libraries default to transporting JSON. So a single bit flip becomes 100+ bytes.

wadecodez
Автор

5:53 I think idle games generally don't allocate/dealocate much of anything after the game starts.

principleshipcoleoid
Автор

That just goes to show that there is a lot of work needed in high-level high-performance languages. Rust is certainly a step in the right direction, but it's not exactly easy to use. The problem is that for over a decade or so, on the back of exponential hardware performance improvement developers collectively decided that performance is not even a secondary concern, it's a 10th or 20th priority. And that's just usually a very bad decision. It's possible to spend too much time worrying about performance, but nowadays 99.9% of people spend too little time worrying about performance. And languages that are used for boosting developer productivity - don't help either. They encourage trade offs where the resulting code is not only slow but it's also inherently unoptimizable without a complete rewrite.

julkiewitz
Автор

Dam he made it at least 8 minutes without bringing up rust.

NotTheHeroStudios
Автор

The algorithm comparison is only useful in the sense that it shows any non trivial algorithm implemented in js could have performance within an order of magnitude of C. Prior to V8 this would not have been the case.

Talk
Автор

I did a quick (not strictly scientific) test on my channel, making a very simple API using SQLLite to select a single record.
Where I did ECMA/NODJES vs C++ and sure after some linux kernel tuning the C++ was a lot faster but JavaScript did impress for an interpreted single language interpreter. The memory usage of NodeJS consuming I believe it was 90MB resident vs 5MB of the C++ was more of a concern than the slower processing.

CallousCoder
Автор

Your general feeling matches mine. JavaScript is easy to write in many ways and I find it highly productive. Performance goes out the window when you start allocating a bunch of memory. Keep your critical paths at a low memory footprint and you get much better performance. You really 'optimize' by minimizing the use of the GC.

brandonmansfield
Автор

I would love a video on writing fast JavaScript. You're so experienced that you can explain complicated things simply

jsonisbored
Автор

I actually know a compiler dev from the V8 team. He complains still that this was the hardest things he could ever imagine.

topticktom
Автор

haven’t watched yet, but SimonDev is great, love this guy

jakobbouchard
Автор

1:36 You heard it hear, folks! Prime says "Javascript is awesome!"

jmnoob
Автор

This also ignores how c++ could be optimized further with things like const and pure attributes if he uses gcc. It also ignores the fact if it was a simple expression you could also write it to be constexpr to let the compiler do all the math for you.

Joe-xrxl
Автор

It's so strange to hear "X is the reason why JavaScript is *awesome* " from Prime.

Dev-Siri
Автор

Hey... Some input from a Python dev here. I had to develop and algorithm that copies together some images in memory with some rudimentary scaling applied, something that was not really possible via a standard library. It was okay but not fast enough in Python+Numpy - something in the ballpark of 5-10 ms. So I dusted off my C++ knowledge, thougt really hard about data structures. Realized that I could do some trickery with memory remapping and that 5-10ms operation became... microseconds pretty much. It was mad. 1000x optimization. Best case was 100ns because no memory had to be copied (which was the only way to do it in Python) but it could be virtually relocated so "moving" an image from one place to another became a mere update to a pointer (sortof... mmap is cool). I totally forgot how fast C++/machine level code can be if you know what you are doing. Lol

MrRecorder
Автор

Integrals?
@4:00 The C++ code was all run without any mem allocation after initial setup, no? Is it a test of memory access speed. Is JS code operating on an array or a Buffer. Are JS Buffers efficient for anything other than ints? Key point is that it is NOT always allocation and garbage collection. Access patterns can effect performance. If operations are done sequentiall for each element of several column vectors, it matters whether the matrix is stored by column or by row. By column, you may have a cache miss per operation.

Port what works, optimize what's needed. If a compiler will improve your code let the compiler do it first before you meddle with it.

NuncNuncNuncNunc
Автор

I made a few games in JS, I think the biggest time waster is debugging.
4x slower to run 20x slower to code.

cubbucca
Автор

He somehow always turns it into a Rust ad

JRAN
Автор

Be careful when you JIT, otherwise you might end up like me

tdotgg