Enable --!native for clients

Problem

As a Roblox developer, it is currently too hard to write performant LUA code that works on low end devices, especially when there’s lots of moving parts on the client or when the client is processing a heavy workload.

Use Cases

The following use cases are presented.

Use Case 1

In my game, depending on the map, I have quite a few items that float up and down on a sine function, and rotate. All the items get this treatment for each tick of RunService.RenderStepped. Therefore, I have to run a for loop inside the event handler. I have done some tricks such as pre-processing as much of the data before hand as possible and not running the loop every time to help alleviate this, but it’s still an issue on lower end machines. This is generally a compute intensive task as the delta time from the engine is used to calculate the angle increment from the parameters on the parts themselves.

Use Case 2

Some on demand effects, such as lightning, are compute intensive as the position and orientation of each part that makes up the bolt must be calculated independently, and it relies on the location and orientation of the previous part so it can link up and look visually correct.

Additional Information

Although Roblox does support Parallel LUA, there are some very strict requirements in place which makes using Parallel LUA for effects mostly impossible since properties of instances cannot be written to in parallel mode, which is a design limitation albeit for thread safety for the engine. This means that even when using Actors to separate code into multiple threads, one is still forced to enter single thread mode to run the effects.

Conclusion

If Roblox is able to address this issue, it would improve my development experience because my code will run more efficiently on lower end devices and not bury the device in work that it will never catch up on.

8 Likes

I don’t understand this feature request. What is it that is being requested? --!native can already be declared at the top of the script to enable native codegen - and it wont always provide that big of the performance boost depending on what is being executed.

4 Likes

It only works for servers, not clients.

4 Likes

iirc, a staff member said they were already looking into doing this

4 Likes

Clients have actors, servers have native codegen.
Sadly its too difficult to write exploit-free native codegen processing code.

e.g. a few months ago a bug existed which shifted variables registers so:

local a = buffer.create(16)
local b = 1

In this code, if you did certain buffer writes, the registers would shift and “a” would get shifted to have the value of “b”. (this was fixed a long time ago dont get too hyped)

Now imagine if this was used to gain access to certain restricted items — maybe this ends up in a sandbox escape — things would go south pretty fast.

Roblox’s reputation would be highly damaged after an attack causes some devices to get infected.

Im guessing the reason this feature was released on servers in the first place was because they are sandboxed and security measures everywhere.

We probably have to wait a few more years until the developers are sure there are no sandbox escapes or native code is fully sandboxed.

5 Likes

Oh I completely overlooked that lol, my bad.

1 Like

what native does anyway?

llllllll

2 Likes

It’s a directive to the engine to compile the script into native machine code instead of the byte code for interpretation. Machine codes runs directly on the CPU at CPU speed, which significantly increases the performance of the code over interpretation.

1 Like

--!native is a flag that compiles Luau bytecode to direct machine assembly through a process called JIT compilation. The issue is Apple.

Apple. Apple and its hate for JIT compilation

2 Likes

PHP and JavaScript do this as well. I think other interpreted languages like Python and Ruby also do this. I haven’t heard anything about Apple hating JITC. Would you please elaborate? Have they stated any reasons?

apple only allows jit on web browser apps. they are pretty strict with this stuff as it could lead to security vulnerabilities, being able to generate executable code on the fly

1 Like

Lua doesn’t use a stack because it’s register-based (it uses a return stack for function calls, but that’s unrelated). I have no idea what bug you are talking about because shifting registers should be impossible since they’re unsequenced.

Luau native codegen isn’t JIT-compiled, it’s AOT-compiled.

Still, Apple does not permit running dynamic assembly on its chips, to the hardware level. This is the same reason Minecraft had to be rewritten in C++, because the JVM wouldn’t work on iOS.

2 Likes

The bug I was trying to explain was on the native codegen announcement

It was also a weird bug, never got to reproduce it with simpler steps as whenever I changed even a loop it stopped functioning that way.

WheretIB had also verified this was a bug (yippe)

Yes, I meant the registers sorry for the misinformation. Will fix that now. :sweat:

1 Like

Here’s the issue that I have. Since the code is precompiled before the client downloads it, I wouldn’t call that dynamic assembly. The code is compiled on publish and then sent to the device when the device logs into the server. I don’t see the problem here.