What is --!optimize doing?

I haven’t touched Luau in about 1 year at this point and I was going over some code and it has the tag --!optimize 2 on it, apparently there’s levels, but and I actually remember looking at this a while ago and seeing a post on it here on the forums, and now it’s impossible to find and I can’t find any data whatsoever on how the hell this feature works. Also does this impact live environments as well as Studio environments?

Another thing does this break any code? What kinds of code would it break?

Have you looked at this Post?

That post is about type checking and I can’t find anything about --!optimize even if I search it. I already very much know type checking tags.

I figured it out after searching very hard with specific tags and everything, turns out DevForum search is worse than bad.

These optimizations are basically things that the compiler is confident enough about that it’ll not actually do calculation, for example string.byte("A") is always returning 1 character since that string isn’t gonna ever change, it isn’t a variable or anything so it’s always true. The only exception would be modifying stuff using getfenv() which ofc breaks a lot more than just that. I would expect this feature to break some debugging features if you use those and that’s why it’s not a thing by default on Studio. There might be more optimizations involved that I’m not aware of, that’s just one that seems to be basically confirmed.

  • This seems to be Studio only AFAIK, if you’re gonna use it, leave it at optimization level 2 since it’s the same as live. I would guess 0 is like 0 optimization and so it should be basically pre-luau days. Not sure. Don’t go around saying it is because this is an actual UNDOCUMENTED feature that has no actual info on it, the only thing you can rely on, is setting writing --!optimize 2 should result in the closest performance as live as possible while in-Studio.
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.