Optimizing the LuaU Runtime

Hey everyone, I’m back!

I’ve been messing around with an experimental Luau fork and some native Studio patches that make a few common scripting operations cheaper under the hood. So far I’ve worked on table creation, unpacking, moving data around, string ops, numeric sorting, and packed-bit access. The goal is that existing scripts can just get faster without anyone having to rewrite them.

For devs this could mean snappier procedural generation, data processing, and other script-heavy stuff. I’m also poking at rendering bottlenecks to see if any native-level changes can help FPS without changing how things look.

Quick note: the big speedups in the previews are from targeted stress tests, not full-game FPS gains. These patches only work on a specific Windows Studio build right now, and players wouldn’t see any benefit in live games unless Roblox decided to ship something similar.

Still early days, but I’ll keep sharing comparisons, results, and the limitations as I dig deeper. What kinds of workloads would you guys want me to test next?

search-before-after
unpack-before-after
bits-before-after
case-before-after

23 Likes

@Yarik_superpro i think you might like this

7 Likes

Could you give any insight on how these optimizations work? I do wanna hear something about it, the string.find optimization seems crazy

4 Likes

I’m optimizing the native C++ code behind Luau’s built-in functions. For plain “string.find”, the original algorithm can repeatedly compare nearly identical sections of text. I replaced that search with a linear-time algorithm that avoids the repeated work and returns the same result.

The whole program will be put on github and open sourced for anyone to make PRs on, and maintained by me as long as there’s enough people that are interested

4 Likes

maybe you can submit your optimizations to the main luau branch

3 Likes

I’ve considered it, but major compiler optimizations tend to face pretty strict review requirements, especially around regressions, compatibility, and maintainability. I’d rather refine and benchmark the changes thoroughly before attempting an upstream PR, since a substantial rewrite isn’t necessarily something they’d want to merge. But it will be really easy for any developer to apply to their studio as it’s packaged into a runnable .exe file (as I’m writing this out I realize I should probably add Mac and Linux compatibility).

1 Like

These are runtime optimisations though? Touching the VM execution itself will probably get scrutiny but a few library functions? I dont think it’ll be treated as harshly. They’ll probably consider backwards compat and memory bugs more than anything else.

Also I’m sure theres a lot of performance to be gained in the VM itself, some of the opcodes are uh, a bit unclean to say the least.

3 Likes

First native FPS patch for the project: +6.6% FPS in a controlled Studio stress test.

It shortens the engine’s path for reading Part positions during render-priority calculations, cutting unnecessary function calls when the transform is already up to date. Same scene and graphics quality; gains will vary by game.

3 Likes

Yeah, runtime optimizations is more accurate. Most changes are to Luau’s C++ library functions so far. I’d like to explore the VM too eventually, I’ll probably look into that a bit tomorrow, I appreciate the suggestion btw

1 Like


Native text-layout patch: +8.6% FPS in an 8,000-label Studio stress test. It skips two deep style copies when only a number is needed. Same fonts and graphics. Local prototype, not a general gameplay FPS gain.

2 Likes

@Yarik_superpro IS ts pro, vro ? ? ?

5 Likes

Some more findings from the last couple days of thorough searching…


1 Like

Public Repository Ready For Early Testing
IMPORTANT: Feedback welcome, but do be aware it is still very early, and prone to having bugs. I usually wouldn’t recommend this but as of now do not apply this to your main machines native studio, this release is more for developers who want to contribute PRS on separate machines, tailscale funnels or VMS that aren’t as important to your workflow.

1 Like

Lots of updates since I last checked in, anyone that’s interested check the merged pull requests.