Lua
Of course I would think that adding Lua as a rendering pipeline would reduce performance significantly, but I never imagined it would be to such degree. On Christmas and New Years holidays I had some free time I wanted to spend on a side project, just seeing how it would turn out. As mentioned previously, I started with creating the library loading and all the utility features around that, which was surprisingly both easy and straightforward. I later threw it at PixelMap, and with a bunch of refactorization to both make it secure and efficient, I added an ENABLE_EXPORTS
to allow the internal features to be visible from any library. The library I created was throw into a second repository and a couple of dependency variables were required so it did not have to include those as well.
For Lua, I had to go through the reference manual to figure out how it worked at all. I then managed to implement a couple of C++ features that I deemed necessary, like std::function
support, field registration, object creation and destruction, and basic std::vector
support. I do know that there exist much better libraries already, but I really wanted to dig into this without any unnecessary dependencies, while I learned more about how Lua stacks worked. Then I added in all the rendering features, including some necessary basic class and glm support. Finally I wrote the script file.
While all this was done, I just had to spend hours debugging loads of segmentation faults, crashes and odd errors. I previously had one global state, which Lua does not like, so I instead from it created new threads, so each integration was separated. I also fixed a stack overflow while creating new threads (Using the registry as storage to avoid garbage collection), and finally succumbed to pressure and created individual states for each thread. Here is where the performance plummeted, with almost 300 times worse performance as native rendering(16 times for total time, but that does not matter). I suspect this is due to the poorly integration from my side, but also due to overhead between Lua and C++, in addition to the creation of a Lua state and initialization of classes for each thread. This is just assumptions, and it doesn’t really generate the image I wanted, even though the script should be exactly like the native implementation. If I could get threads to work properly(probably due to registry issues), it might improve the performance somewhat.
I will finalize the module and maybe release the Lua module as an example on how it can be integrated. I probably need to redo it a bit to allow more features later on, maybe even enable the possibility for GPGPU or SIMD. I will see where this will escalate, but probably I will need to spend more time on other things as most script languages is inferior to C++ when it comes to performance.