Luau Native Code Generation Preview [Studio Beta]

Interesting. I’m using an Apple Mac Mini, M2 chip with 8-core CPU and 10-core GPU, and 16 GB of RAM.

1 Like

Actually, this seems to very likely be an Apple-silicon problem. I tested this on my old Intel 2018 13" MacBook Pro with Intel Iris Plus Graphics 655 and 8 GB of RAM, and like you, there was no difference between A and B.

Screenshot 2024-01-11 at 2.07.59 PM

1 Like

Did you guys experience the same issue with Apple Silicon computers? A fix would be appreciated.

1 Like

Thanks for the info, we have found the source of the issue on Apple HW.

3 Likes

How am I just knowing about this now! This is so cool! So basically luau is the same as the native script beside native script having faster times and luau supporting more devices? Are there any other differences?

1 Like

Weird issue where when I do some specific stuff my buffer variable holds a different variable.
I really don’t understand what’s causing it.

--!native

local Buffer = buffer.create(1);

buffer.writeu8(Buffer, 0, 0); --// We need to write to the buffer or else it doesnt work

local Var1;
local Var2 = "Hello, World!";

--[[
	having "Var1" and "Var2" above causes the "Buffer" variable to hold "Var2" value.
]]

local function Bug()
	--// If done right (what is even the right way) our "Buffer" variable now holds "Hello, World!"
	
	if type(Buffer) ~= "buffer" then
		warn("Buffer new value:", typeof(Buffer), Buffer);
		error("Buffer is no longer a buffer!!", 0);
	end

	--// 2 lines of code below here actually doesnt matter but "Buffer" variable doesnt change when we remove anything below here.
	repeat pcall(1) until true;
	Var1 = nil;
end


--// Doesnt make much sense but we also need this in a loop
repeat
	Bug();
until true

if type(Buffer) == "buffer" then
	--// Warn in console if our variable did not get changed
	warn("Code ran as expected. (variable was not modified)");
end

Code works as expected without native execution.
As you can also probably tell I found this completely on accident so the code is kinda messy.

My CPU is AMD FX-8300 overclocked to 3.8GHz

I’m so confused :sweat_smile:

1 Like

It’s a bug, thank you for the report.
We’ll fix it with a release in a few weeks.

1 Like

Good that roblox knows Compiled > Interpreted

This issue has been fixed, sorry for the confusion we caused.

2 Likes

Code making heavy use of vector3s appear to run worse when using --!native, an extreme example being:

local t: Vector3 = Vector3.new(0, 0, 0)
local a: Vector3 = Vector3.new(1, 2, 3)
for z = 1, 10 do
	wait()
	local t0 = os.clock()
	for i = 1, 1000000 do
		t += a; t += a;
		t += a; t += a;
		t += a; t += a;
		t += a; t += a;
		t += a; t += a;
	end
	print(os.clock() - t0)
end

runs about 20% slower with --!native enabled.

Seeing some recent changes to the Luau GitHub repository, will it be soon that Vector3’s get some much desired performance increases?

Unfortunately, Vector3 support is still lacking and we couldn’t deliver the improvements in December as previously mentioned.

As a workaround, in same cases you can wrap into a function with Vector3 arguments:

--!native

local function work(t: Vector3, a: Vector3)
	for z = 1, 10 do
		wait()
		local t0 = os.clock()
		for i = 1, 1000000 do
			t += a; t += a;
			t += a; t += a;
			t += a; t += a;
			t += a; t += a;
			t += a; t += a;
		end
		print(os.clock() - t0)
	end
end

local t: Vector3 = Vector3.new(0, 0, 0)
local a: Vector3 = Vector3.new(1, 2, 3)

work(t, a)

No, it will not be soon.

2 Likes

I suppose one final question,

When is native Luau planned to release to servers?

1 Like

We plan to release it this year.

5 Likes

“It is written: ‘Lua shall not live on interpreter alone, but on every instruction’”

  • John Lua.

Anyways, Great job on this! Super interesting and I will look through the opensource luau-codegen on GitHub and experiment on it.

One thing I wish for is struct’s and union’s like in nelua, which does compile to C. It could result in huge memory performance increases when used correctly.

Compilers & Transpilers or just low-level programming has been an interest of mine. How does native codegen handle dynamic typing, do they all just have an accompanying variable that holds the type and the value itself is stored as a int?

Each value has a corresponding type tag alongside with it.

2 Likes

Getting this error

Native code generation of script =ReplicatedStorage.WindShake.Octree.OctreeRegionUtils failed: Allocation error. Script will be interpreted.

You need to make your script smaller.

Alternatively, if you have a lot of native scripts, you might have to disable it for some of them to get back under the memory limit.

We’re back, baby. The code I am infamous for is making its return.

In the before times (<2020), code using three local variable numbers was faster than using Vector3.
Then, with the release of Native Vector3 in 2020, Vector3s and three local numbers performance converged, and with that I switched over to using Vector3s for performance sensitive code, just for the increased readability.
Then, in 2023 with the release of Native Code Compilation, three local variables are once again the fastest by a factor of 3x in real code, and I have changed our modules to reflect this.


We’re going from 6us to 2us, amazing for a dynamically typed language like Luau.

I am ecstatic, and cannot wait for the release of --!native.

8 Likes

Any updates on Vector3 performance?

2 Likes

Will we finally be able to create classes?