Optimizing Lua for embedded processor? [closed]
Asked Answered
H

0

7

I am embedding Lua in a programm for no-eabi device with 16Mhz 32-bit ARM7TDMI processor and 256Kb RAM (yes, that's GBA). Currently it's working flawlessly (thank you, StackOveflow users, for answering my questions), doing easy tasks, but what optimizations I can do to perform overall efficiency? Here's some of my thoughts:

  • Currently I am storing my Lua code as constant char array (there's separate ROM up to 32Mb, so it helps to free RAM). When I want to run it I just push this string to Lua stack and "pcall" it. But as I know, Lua builds that code into byte-code in RAM. I thoght that can be some problems with big Lua files too. Any way-to precompile that byte-code and save it to constant container too?

  • Which asm command set is better for running Lua - THUMB or ARM?

EDIT: Maybe, changing vanilla Lua to LuaJIT? As I know, LuaJIT has many assembly lines of code (which makes it less portable), any chance to perform successful build to old ARM7 processors?

Heel answered 15/4, 2016 at 13:14 Comment(2)
You can compile the lua to bytecode and then run that directly but that might lose you space in terms of code size and probably won't improve loading performance much (if at all). There have been threads about this on the lua mailing list over the years that it might be worth seeking out. You should probably also actually benchmark your process to see what parts are actually slow before attempting to optimize.Mentalism
Precompile any scripts you can into byte-code in ROM, switch to an integer number type and shuffling the byte-code executor and other core functions to full ARM code in IWRAM. Mostly, though, performance will be a matter of writing sane Lua code with care and attention put into the division of labor between native C API and the Lua code. Ideally on such a limited platform you want to be doing the wast majority of the low-level work and memory management in native code, leaving mostly special-case hooks and high-level decision to the scripts.Digiovanni

© 2022 - 2024 — McMap. All rights reserved.