New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AP_Scripting: move singleton method bindings to flash #18249
Conversation
|
639eba4
to
49b0122
Compare
great! |
@WickedShell this is really interesting for scripting I think, do you have some time to review it ? |
49b0122
to
68a3df8
Compare
Now implemented the same approach for all singletons, ap_objects and userdata types. Still in memory are the manual bindings and the custom uint32 handling. Simple loop on master uses Looks like were picking up about 1k in flash. Not too bad on the whole. I think the main thing now is to test this on lots of different scripts and make sure I have not broken anything and that the runtime memory usage and execution time is not adversely affected. |
@@ -2379,6 +2396,43 @@ void emit_docs(struct userdata *node, int is_userdata, int emit_creation) { | |||
} | |||
|
|||
|
|||
void emit_index_helpers(void) { | |||
fprintf(source, "static bool load_function(lua_State *L, const luaL_Reg *list, const uint8_t length, const char* name) {\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get accurate timing on a STM32 need to do the same as ENABLE_EKF_TIMING does
#if ENABLE_EKF_TIMING
void *istate = hal.scheduler->disable_interrupts_save();
static uint32_t timing_start_us;
timing_start_us = dal.micros();
#endif
a benchmark like Tools/CPUInfo would be very useful, along with disabling interrupts |
This test script:
Master: This PR: edit: Forgot to mention that the testing was done on a Pixhawk1 So approx double the run time, Master memory: This PR: A saving of |
This changes the singleton enum and method tables to be evaluated in
c++
, so they stay in flash and we don't have to load them into memory for lua to use. This method seems to work, no changes required to any scripts.This is the memory usage of the simple loop example for master:
AP: Lua: Time: 0 Mem: 52879 + 72
And with this PR:
AP: Lua: Time: 0 Mem: 40312 + 616
So we save 12.5k of memory total but has a bigger increase of +544, I suspect that means I have not got this quite right.
If we pick up that much on a simple script the memory saving may not be worth it with bigger scripts.Seems to not scale and sometimes not pick up anything, I maybe there is some interaction with the garbage clean?This also costs about 1.6K of flash.
I have only done singletons here, we could pickup some more savings by also doing userdata and ap object types.
The are also probably better ways to do this if you know what your doing. It would be nice to grab the singleton in the indexing function and then pass it down to the method function, that would save lots of flash, but I don't know how to do that.
I have not investigated how this effects run times, or the total memory used by the scripting thread.
To get a better idea of what is going on it is easier to compare the generated bindings directly rather than comparing the binding generator.