PS. I do investigate now why LUA is so fast.. I do not understand how LUA workflow processed, so I just do debug output to file ticks of enter and leave LUA points.
ubasic (current version without your path) only runs one line per kbd_task loop iteration, except for REMs and labels (and the latter was an optimization I added some time ago). Lua runs 1000 lua vm instructions between yields.
In both cases, this is needed to keep kbd task running at a reasonable rate.
I think making ubasic run more than one line per kbd_task iteration is a good thing, as long as you make sure to yield for all the things that need to do it right away (which a quick glance at your patch suggests it does)
If you are going to do it based on time, I'd say 10ms (the smallest increment get_tick_count measures) would be a better choice, otherwise kbd_task iterations will take much longer than the camera expects and this could have side effects. Doing some fixed number of cycles like lua would be another option.
If I was going to merge this, I'd rather not have unrelated ubasic optimizations in the same patch. Just more than one line per cycles will make it orders of magnitude faster. Note that even running 1000 instructions per kbd task, the yield time is by far the limiting factor in lua performance:
http://chdk.setepontos.com/index.php?topic=6729.msg71456#msg71456 but this simply isn't a problem for most scripting tasks.
I'm not personally not inclined to expend much effort on ubasic, Lua is a far better language, and the effort to bring ubasic to anything close to that standard would be huge. Not performance , but things like multi-letter variable names, local variables, strings, tables, functions, file io...
That doesn't mean I won't apply improvements for ubasic, but if they take me a lot of work to understand and apply, that certainly won't count in their favor.
If you have problems with lua running out of memory or crashing from other things, I'd say the effort would be much better spent debugging those.