Optimizing performance for 1000 units
construct.net
construct.net
Yes I can attest to that. In my day job I write JS code that processes images in 2D. Processing images, even of a high resolution through simple algorithm is perfectly doable at 60 fps in JS. You just have a to be careful to what you do but that's pretty much true for any language.
Recently, I implemented a bilinear interpolation in JS, C (wasm) and WebGL. The C version was only marginally faster than the JS version even though the whole set of optimization was on. Sure native C would probably be significantly faster but then you wouldn't compare languages but runtimes.
To explain further, I'm also not surprised that hand tuned assembler can get the same performance as compiled C.
When people bitch about that JS is so bloated and slow, it's usually because of things interacting with the DOM and everything related to it, or just slow network connections. But then people take out their frustrations on the language instead.
Often the problem is probably that people are making too many DOM nodes (no virtualization), talking to the DOM inefficiently via a slow framework (React) and talking to the framework inefficiently (bad code).
Not sure what you mean by this. Every time I run something like document.getElementById(), it is very fast.
Well you must be smarter than I am (which is not saying much).
For my grug brain, an untyped memory-managed interpreted language will be at a significant disadvantage against a typed compiled language whatever the use case. It's a testament to the Chrome dev team's hard work.
It is also possible that the WASM VM has not benefited from as much love as the JS VM.
What remains then, is compiling to native. This is where C shines and Javascript doesn't. Because of it's data model, Javascript just can't take advantage of what you could do in plain C.
0: This rambling "explanation" is exhibit A
Looking at the unoptimized code itself, it's getting ~150 MFLOPs which is close to C/C++ in the sense that it's only 10-20x slower than what a single core can do before manually doing any vectorization.
It's getting lost with unity/unreal and their asset store that bastardize the craft
But when you are on a mission to make a specific kind of game works, that's when you appreciate the smart people working in that industry, what ever you want on the screen, they'll make it happen, what ever it takes
You can measure the frame start and end time (duration) and divide 1000/average duration over 1 second. This will give you the render speed even if that's not the actual number of rendered frames.
Went from 5-15 to 45-60 FPS during battles with hundreds of units. I even enjoyed the little fine tuning/cheating here and there that reminded me of the real games I've been playing my entire life. I was moderately happy at this ungrateful, low paying job.