08-30-2017, 12:44 AM
I've finally brought my new API idea from #252 ( https://forum.cuberite.org/thread-2727-p...l#pid28462 ) to a fully compilable and runnable life. It seems it's actually working, and additionally has a nice bonus of being ~7 % faster than the old style (tested with a single-signature API function). Adding and actually using an overload signature is a bit difficult to measure, but I assume it would perform even better than an equivalent old-style code; the old style performs unneeded double-checks which the new code doesn't do.
As for some real data:
Old style interface with only single signature: 3.012 seconds per 1000 000 API calls
New style interface, first signature used: 2.803 seconds per 1 000 000 API calls
New style interface, second signature used: 3.766 seconds per 1 000 000 API calls
I didn't test an old-style interface with multiple signatures. Anyway, the times show how unimportant the cost is - about 3 microseconds per call.
Because the cLuaState class is already quite large, I decided to put the new coed into a separate namespace-like class, cLuaStateParams. So this is an example code that actually works with the new style:
Now to see if the whole thing compiles under clang / gcc
As for some real data:
Old style interface with only single signature: 3.012 seconds per 1000 000 API calls
New style interface, first signature used: 2.803 seconds per 1 000 000 API calls
New style interface, second signature used: 3.766 seconds per 1 000 000 API calls
I didn't test an old-style interface with multiple signatures. Anyway, the times show how unimportant the cost is - about 3 microseconds per call.
Because the cLuaState class is already quite large, I decided to put the new coed into a separate namespace-like class, cLuaStateParams. So this is an example code that actually works with the new style:
static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState) { cLuaState L(a_LuaState); cServer * Server; AString Name, Version; UInt32 Protocol; switch (cLuaStateParams::Read(L, std::tie(cLuaStateParams::self(Server), Name, Version, Protocol), std::tie(cLuaStateParams::staticSelf<cServer>(), Name, Version, Protocol) )) { case 0: { Server->RegisterForgeMod(Name, Version, Protocol); break; } case 1: { cServer::Get()->RegisterForgeMod(Name, Version, Protocol); break; } } return 0; }
Now to see if the whole thing compiles under clang / gcc