Tuesday, October 20, 2015

End Of (Summer) Days

Progress has been delayed, but I'm still working on getting all of the pieces back together. The widget system rework was already taking longer than I expected and in the process, I decided to bear down on the part that I consider most important.

Mana's object system must be easy to use and as fast as possible.

Since Lua is the scripting language that drives Mana functionality, I was concerned about certain performance bottlenecks. I'd been using Lua's C-API for connecting Mana and Lua. In an attempt to keep as much as possible on the C (BlitzMax) side, I wrote all of Lua's metatable access functions* in BlitzMax and put all of the exposed functions in a hash table. Then it occurred to me that doing it that way would result in very (extremely) inefficient look ups. Sure enough, a few tests confirmed my worries.

This revelation led me to do some digging on the LuaJIT forums and eventually decide to rewrite a significant portion of the Lua interface code. LuaJIT has an FFI, or Foreign Function Interface, that allows Lua to directly call C functions and best of all, they are inlined - in other words, fast!

The decision has added almost two months to my plan, but the resulting speed gain on non-engine related logic should be a factor of three to thirty or more!

* Lua doesn't have objects, per se. Without getting too technical (...), it uses tables to store object data. The tables have special attached functions (methods) that control data access. These methods can be redefined in ways that change, to some extent, the way the language works. This feature makes Lua particularly suitable for customization and great for scripting.

No comments:

Post a Comment