RobLoach / node-raylib

Node.js bindings for Raylib
https://robloach.github.io/node-raylib/
Other
237 stars 20 forks source link

generator: flatten structs & use refs better for more performance #114

Open konsumer opened 2 years ago

konsumer commented 2 years ago

@twuky found that flattening structs on in/out gains some major performance. Here are the metrics on my system (linux, RTX 3050):

current

Screenshot from 2022-02-22 13-02-17

proposed

On twuky's tests I get insanely good FPS:

method: DrawTexture, args: 4, bunnies: 14920
method: DrawTextureNew, args: 4, bunnies: 95750
method: DrawTextureNewWhite, args: 4, bunnies: 100820
method: DrawTextureShortInt, args: 6, bunnies: 1000
method: DrawTexturePointer, args: 4, bunnies: 1000
method: DrawTextureShortWhite, args: 5, bunnies: 89900
method: DrawTextureShort, args: 9, bunnies: 65430
method: DrawBunnyWhite, args: 2, bunnies: 101670
method: DrawBunny, args: 6, bunnies: 79460
method: DrawBunnyBuffer, args: 1, bunnies: 55580
method: DrawTextureFlat, args: 11, bunnies: 62720
method: DrawTextureFlatWhite, args: 7, bunnies: 78390
method: DrawTextureShortBuffer, args: 6, bunnies: 65410

It's not a totally fair comparison, in the sense that branch has other optimizations (which we should also add to the generator) but the flat thing by itself will help, and refs will also help. We should try to do both in the generated code.

twuky commented 2 years ago

For more details on how the experimental benchmarks I wrote were implemented - reference https://github.com/RobLoach/node-raylib/issues/100#issuecomment-1046400083

Some documentation on what flattening arguments looks like in C++ and JS can be found in the raylib4 branch, in the generator docs: https://github.com/RobLoach/node-raylib/blob/raylib4/docs/generator/flattening_arguments.md

RobLoach commented 2 years ago

Wow!