This would do great for my game where I compute a bunch of visual effects all on the CPU. Was pretty saddening to work on an effect, optimize it to run well, publish it and see the performance is about 6x worse than I saw in studio thanks to --native only working on LocalScripts in Studio.
I get native codegen takes a lot of caution to implement safely but I’m remaining hopeful that it can be done someday.
I can definitely agree, doing visual effects with code would benefit lots from --native! The only thing that would make it even better is Write Access in Parallel Lua. I hope more optimization features get added, I have spent many days trying to optimize my effects and yet with the current systems we do have, I think I have hit the limit. I can’t optimize it anymore than I already have. I can achieve about 1k~ parts being animated at 60fps on an empty baseplate and I am always looking for ways to improve it! --native is one of those was to improve it. Please roblox add this!
Very different use cases here, I think it’s worth mentioning I only saw a 6x performance decrease in Player because of the code I was benchmarking.
The effect I was referring to in my message you could probably call a shader? I was doing per-pixel modification of an EditableImage buffer to change the final look of it. And it’s this heavy usage of buffer math operations that is listed in the best practices for native code generation.
So while Native Codegen is cool and all I’m not sure how much it will benefit you when it comes to animating parts. A lot of things like the CFrame matrix math is already handled natively.
Most of the benefit I would get would be from the frame generation step, where all the frames of a given effect are generated on creation before being ran.
I’m working on a drawing game and this is the exact wall I just hit trying to do custom blend modes and filters. I may have to omit these features for now as running a loop over the pixels in the buffer is just too slow with JIT for gameplay. I’d really appreciate native speed for client scripting! Fragment/vertex shaders for editable images/meshes would be even better, but unfortunately I don’t count on Roblox being willing to add anything cool like that…
--!native tells it to compile to machine code (Native Codegen a.k.a. NCG) if possible. Opcodes are what the VM (interpreter) uses. Native codegen can make math-heavy code a lot faster, not “negligibly”.
VM pretends to be a CPU in a way and calls them Operation Codes anyway. I would suspect that this distinction doesn’t really matter if the people who have to maintain systems that use both are making such a “mistake”. Indeed, they call the operation IDs “Bytecode opcodes”
Perhaps for Luau, bytecode is the entire binary data, containing both opcodes and the data they operate on.
This distinction only matters if you want to talk about CPU-ran opcodes or VM-ran bytecodes. In code, this distinction already exists. LuauOpcode is equivalent to LuauBytecode, because last time I checked, there isn’t a CPU instruction set named Luau.
I have noticed that people are still posting on this topic, even 1-1/2 years later. So if this is not possible, I have a workaround to it:
Take the top several thousand most used code operations and bundle them into a client only library and compile that to machine code and include it into the client download package. AI can help with the analysis of this. So if it can’t be done, some of the longer, compute heavy operations can be converted to native code in a Roblox provided library which will help with client performance.
For instance, if you have 20,000 games that use five functions that are similarly coded and are math heavy, you can unify the implementation of each of those 5 functions and add them to the library. In computer science, there are only so many ways to solve a problem. An example would be functions that compute the rotation of an object in X, Y, Z or have an object cycle float up and down (or both). Granted, a lot of LUA code is simplistic, but there are pieces of code that’s semi-intelligent and not trivial. It’s that code that should get the native treatment.