Maximum size of LUA code?

For a lot of reasons (lookup tables, data formatting and mapping, crazy logic, multiple versions of the OS), I have a preset that has about 2300 lines of LUA. I anticipate it topping out around 3000 or so lines.
After optimization I might be able to bring it down a bit, but still…

My question (other than a max size/max lines) is – would it be possible to create more traditional formats of code with #include<> files and things like that?

This is an edge case for sure, but i could see the desire to have additional common library routines or data tables loaded to the E1 and then other presets could reference them by doing something like

function preset.onLoad()
  #include<MIDI_notes.h>
  #include<bitpacking.h>
end

kinds of things

1 Like

I do recall a post talking about the RAM in the MKII thread:

And some other context in there.

Precompiled lines in any language isn’t a good indicator of program size/memory consumption as you can make a few lines take up tons of memory or have thousands of bit twiddling lines that uses barely any because it’s efficiently packing stuff in memory.

Thanks for that. I wasn’t sure if I remembered Martin posting numbers or not.

I’ve run into situations on the Mk I version where the memory bar looked OK (about 7 out of 10) and then while running, suddenly seeing msgs about out of space.
I know there’s a garbage collector in LUA and I try to keep large temporary storage to a minimum.

The other aspect is more on the practicality side - scrolling through lots of code and data to do edits gets tedious sometimes. I guess I could do more offline and then paste it in later.

| adamc
June 25 |

  • | - |

I do recall a post talking about the RAM in the MKII thread:

Electra One mkII General discussion

There is 64MB on board. 32MB directly accessible with Lua (currently around 150kB) and other 32MB for storing graphical assets, lists, etc.

And some other context in there.

oldgearguy:

I have a preset that has about 2300 lines of LUA. I anticipate it topping out around 3000 or so lines.

Precompiled lines in any language isn’t a good indicator of program size/memory consumption as you can make a few lines take up tons of memory or have thousands of bit twiddling lines that uses barely any because it’s efficiently packing stuff in memory.

Eventually, the current setup is that Lua can use up 24MB of RAM. The Lua stack size is limited to 1MB. The stack lives inside the 24MB memory pool.

mk2 can run up to 12 Lua instances in the same time. These instances share the 24MB RAM and each has its own 1MB limit on the stack size. The parallel Lua instances will be made available in version 3.4. And that one will be released after most the of issues reported by the users (on the version 3.3 - ie. single Lua) will be resolved.

The above guarantees that your Lua can grow big. 2300 lines of code is a lot for single source code file. I am planning to make it possible to use Lua modules (by using the require command). That will make it easier to structure and reuse the code. In the initial phase - for testing purposes - users will be able to upload their Lua modules using the mass storage USB interface of the bootloader. At later stage it will be incorporated to the preset editor. Again this is planned to be part of 3.4.x releases.

5 Likes