Code Optimisation (Especially Buffers)

Hello Devforum, I am wondering if there are any optimisation tips or tricks that can be applied on the client, as native code generation is server-side only.

For a scenario, just imagine the worst of cases, where buffers are read and written to hundreds of thousands of times, if not millions, multiple times a second, a bit extreme, but imagine that.

In studio NCG can be played with on the client, and the performance gain when intensily working with buffers is superior…

I have never worked with actors and parallel Luau on Roblox before, however I am not so sure if it could be useful, as buffer(s) data would have to be sent between actors, which if possible, would probably makes any potential performance gain equal out to about what it was.

So, that being said, is there any optimisation that can be done to increase performance on the client?

Buffers are the tool you use to solve the problem, but in order to properly optimize you need to tell us the problem itself. The more you can restrain the main problem down to a finite set of rules and behavior, the more the room for optimizations.

1 Like

I am talking in general when doing a lot of write operations to buffers.
What I have is a function which writes unsigned bytes to a buffer, around forty million times a second.

Although that runs okay with my computer, adding more operations however, would obviously, decrease performance. An example of that would be if that function also started reading data from “random” offsets in that buffer, and doing math computations, and then write to some offset.
Do note that any code outside of that buffer-writing function barely consumes any performance.

To be clear, I am not attempting to create some specific project, but rather just playing around with the Roblox engine, as I mostly do, testing things that I deem cool and interesting.

So what is the actual point of this post? → As mentioned at the start of the topic, Native Code Generation, also referred to NCG, is only available on the server (for published games, in studio it works on both sides, which is how I know that the performance gain is massive, aka opening up for more computational operations to be ran, with continued good performance).

So, is there any way to increase the performance without NCG, such as adding some of those special comments at the top of the script, or any secret really? (Whatever can be done won’t ever reach the godliness of NCG, but any noticeable performance increase, is a win)

well for parallel Luau buffers is likely not something you want to look for…
Buffers are good untill they aren’t and you should mainly use them for serialization of data to be sent into a datastore becouse that their main purpose.
You may also use buffers for some low level like fast calculations: writing own interpeter (lexer or tokener specifically) etc.
If you want to use parallel Luau you probably want to use SharedTables along with SharedTableRegistry Service

I probably made you even more confused now that i think about it :skull: Don’t worry everything is easier than it seems and its mainly just a “fancy” words to describe simple things.

Nobody calls it like that.
Not even in a documentation.
Please don’t use such terminology

You can use RawLib for micro optimizations aswell as calling methods dirrectly like:

local Clone = game.Clone

local part = Clone(workspace.Baseplate)

Using native code generation is not really worth it becouse AOT Compiler for Luau is not really giving too much benefits and is not as good as interpeter (that is also a little AOT if you consider script analisis)
Keeping code properly typechecked is generally good for both Native Code Generation and interpeter mode as since it benefits script analisis

Parallel luau in state as it is should be considered an “npc ahh lmao” optimization technique as since it is very limited and only usecases i see for it is to compute map data or raycasting validation and raycasting in general.