ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.18k stars 515 forks source link

Binary/Executable size reduction and the removal of simple_usertype #1551

Open EugenCazacu opened 10 months ago

EugenCazacu commented 10 months ago

Hi,

I am looking to decrease the size of executables generated with sol2 which map some C++ interfaces to Lua. I am currently limited to using C++14, therefore I am sticking with sol 2.20.1 for now.

After reading this issue: https://github.com/ThePhD/sol2/issues/295, I switched from new_usertype to new_simple_usertype when mapping usertypes. This decreased the size of the generated binary roughly by half in my tests (from ~1 Mb to 500 Kb for 10 usertypes with 10 functions each), which is right at the target I have.

The documentation of the 2.21.1 version no longer documents new_simple_usertype, although the function is still in the API.

I saw that simple_usertype type is removed fully in sol3 (https://github.com/ThePhD/sol2/issues/776), stating that the compilation and runtime is better with new_usertype implementation. Unfortunately my tests show that the executable size does not decrease with sol3 new_usertype to the same levels as with the old new_simple_usertype.

So far I have tested the generated executable size with a few versions of gcc and clang, with O2, O3 and Os flags. O3 in my tests generates slightly smaller executables. O0 the largest by a factor of 5.

Do you have any additional advice to decrease significantly the executable size using sol with 2.20.1, 3.x and maybe how the binary size of the future sol4 would be? Is there a particular reason not to use the new_simple_usertype from 2.20.1, as it no longer is documented?

Thank you!