ProTip - luasrcdiet to reduce compiled bytecode size
Posted: Thu Oct 05, 2017 3:35 am
I have been doing a fair amount of lua recently for the RCP. I am an experience programmer but have never had to program lua until a few weeks ago. I got very frustrated when my scripts would exceed the max size allowed by the RCP. I understand why the constraints are there but I still wasn't happy about it.
What I discovered is that the compiled lua code includes variable names and other debug information that can bloat the size of the resulting compiled lua bytecode. I like to use friendly global variable names when declaring things like constants and things of that nature. This practice really bloated the size of the resulting compiled LUA code.
Then I discovered luasrcdiet. This project will automatically shorten variable names and functions if they are declared local. The resulting code is unreadable but as far as getting code to fit on the RCP it has proven very effective.
Basically you run your code through luasrcdiet (making sure your code declares local variables as local) and it will allow you to fit much more code on the RCP than it normally would support.
You can find the code on github here:
https://github.com/LuaDist/luasrcdiet
I noticed as much as a 70% reduction in the size of the compiled bytecode. I hope this helps others.
What I discovered is that the compiled lua code includes variable names and other debug information that can bloat the size of the resulting compiled lua bytecode. I like to use friendly global variable names when declaring things like constants and things of that nature. This practice really bloated the size of the resulting compiled LUA code.
Then I discovered luasrcdiet. This project will automatically shorten variable names and functions if they are declared local. The resulting code is unreadable but as far as getting code to fit on the RCP it has proven very effective.
Basically you run your code through luasrcdiet (making sure your code declares local variables as local) and it will allow you to fit much more code on the RCP than it normally would support.
You can find the code on github here:
https://github.com/LuaDist/luasrcdiet
I noticed as much as a 70% reduction in the size of the compiled bytecode. I hope this helps others.