sol2
sol2 copied to clipboard
Provide struct for sol::automagic_flags::none to reduce generated code size
Firstly, thank you for this great library.
I noticed a potential easy way to reduce size of the generated code in case when usertype does not need any automagical detection.
I have some usertypes that are singletons or only expose a few methods. I used sol::no_constructor like this:
auto mySingleton = lua.new_usertype<MySingleton>("MySingleton", sol::no_constructor);
mySingleton["someFunc"] = &MySingleton::someFunc;
auto mySingletonInstance = MySingleton::Instance();
I did an experiment and I saved about 250 KB of object code per usertype (debug mode, MSVC x64) when registering them in this way:
typedef sol::constant_automagic_enrollments<sol::automagic_flags::none> no_automagic;
constexpr no_automagic no_automagic_enrollments { false, false, false, false, false, false, false, false, false };
auto mySingleton = lua.new_usertype<MySingleton>("MySingleton", no_automagic_enrollments);
mySingleton["someFunc"] = &MySingleton::someFunc;
auto mySingletonInstance = MySingleton::Instance();
I think it is worth mentioning in the documentation and providing something like no_automagic_enrollments in the headers so that everyone can benefit from smaller generated code size = faster compile time (even if it is optimized in release).