Hello Creators!
Back in August 2023, we announced Luau Native Code Generation Preview [Studio Beta].
We are now happy to announce that the preview of this feature is now available on Roblox servers and in Roblox Studio without having to enable a Beta feature!
As a refresher, native code generation is the feature that allows Luau scripts that have been previously executed by interpreting bytecode inside the Luau VM to instead compile to machine code that the CPU understands and executes directly.
For more information, including the information on when it’s beneficial to enable native code, we recommend reading both the previous topic as well as the new documentation page: Native Code Generation.
Changes from the Studio Beta
Since the release of the Preview as a Studio Beta feature, we have worked on improving code performance, memory use of the system, correctness, stability as well as integration with the tooling we have available in Roblox Studio.
Some highlights:
- Improved performance of the bit32 library functions
- Improved performance of numerical loops
- Optimized table array and property lookups
- Added native support for new buffer type operations
- Learn more about buffer in the announcement
- Code optimizations based on knowing which types are returned from operations
- Code optimizations based on function argument type annotations
- This includes support for SIMD operations for annotated Vector3 arguments
- Native functions are now marked in the Script Profiler
- Code size of the native functions is included in Luau Heap Profiler
- Native code is now compiled once and reused for all Parallel Luau actors
- Breakpoints and stepping are now supported in native scripts
- Note that native execution is disabled for functions with breakpoints
- You might not be able to see locals of natively executing stack frames
There are many other small improvements in generated code performance and size and we still have a long road ahead of us to continue delivering optimizations.
Upcoming features
While we improved a lot, some things mentioned in the original announcement are still in progress.
- By default, we still do not compile any scripts to native code automatically. In order to enable native code generation you need to put the
--!native
directive on top of your script. - We’ve extended our use of argument type annotations as well as adding some automatic type inference, but we are still missing support for type annotations on locals
- Support for Vector3 has improved for function arguments, but many examples are still not showing performance improvement. We recommend measuring and not using native if the performance doesn’t improve.
Your feedback
If you have already started using native code generation during the Studio Preview, we would love to hear your experience and results with it.
What are the improvements that you are seeing? What are the things that are missing or don’t seem to improve where you expected?
Just like in the Studio Preview announcement, we’re on the lookout for things to prioritize for improvement.
In conclusion, we thank the team members that helped deliver this feature: @DyadicTensor, @lambdazz, @machinamentum, @nullptrchk, @rep_movsb, @welblander, @WheretIB and @zeuxcg!
And a thank you to all who tried the Beta preview out and provided feedback for us to improve.
FAQ
But when will Vector3 support improve?
- While we aimed for improvements to be delivered in December, this turned out to be way more challenging than expected. In our updated roadmap, we expect improvements to come in the nearest months with additional improvements later this year.
When will native execution come to the Roblox Client?
- We are looking into additional opportunities to bring it to more platforms.
Should I enable --!native
for all scripts in the experience?
- We recommend measuring the performance and only using
--!native
for scripts when you see benefits from this feature. Use Script Profiler to measure the performance, which also supports live Roblox Servers!