ErosOlmi
26-02-2009, 13:14
After every new release of thinBasic programming language I stop for a while (2/3 days) to work on thinBasic and work on some other projects, especially work projects. But after that I restart working on thinBasic and usually, every time, I find myself thinking about: how to make thinBasic faster?
I think thinBasic is already quite fast also considering it has no intermediate byte code. But execution speed is never enough so my first thought (when I restart programming at the next version) is speed.
As far as we go on using thinBasic, scripts complexity is increasing. If at first we used thinBasic to create just few lines script and have fun, we are now using thinBasic to make big loops (images or 3D worlds handling), big data handling (we use at work to automate DB tasks an data conversions). In general I see a trend in having scripts more complex than it was before. At the end, more complexity means more code to be executed or the same code executed much more times. All this needs speed and a faster thinBasic Core engine.
I do not want to transform thinBasic into a compiler to have more speed, this mainly for 2 reasons:
I do not have enough capacity, in terms of knowledge and time, to develop a compiler. While I could study more to cover my compiler ignorance, I cannot buy more time at the shop ;)
I love the freedom an interpreted language leave to the programmers and the easy to develop new features and user requests/suggestions.
Back to speed. After version 1.7.7.0 I was checking where, during a script execution, thinBasic was loosing time and I have discovered that most of the execution time is lost during script function execution. And what surprised me was that time is not lost during function code execution but during initial function setup and release. So, in few words, time is mainly lost in allocating memory to adjust variables (local stack used to store local variables and function parameters) and when function execution ends its life (time to take to de-allocate the just created local stack).
What thinBasic Core is doing in the initial and final stage of a script function execution is quite complex and involves the creation of many dynamic structures all connected by pointer in many nested levels. I was thinking on how to avoid all those many allocations every time a function is executed considering that the first time a function is executed I have all the pieces of the puzzle so I could think of a way to do such a time consuming steps only the very first time a function is executed. At the end, instead of releasing all the memory I need to reset used memory.
The biggest problem I can think about is when a user function is executed recursively. In this case I need to allocate further local stack levels for every recursive function execution and release them at the end.
I already started to work on this strategical change and I have to say that initial results are very very promising: around 80% execution speed improvement but I didn’t apply all the optimizations I have in mind.
But I also have a lot of GPF to fix :D Honestly I expected those GPF because this change touch many lines of code and complex memory structures. So my next “week thinBasic time” will be dedicated to this.
Ciao
Eros
I think thinBasic is already quite fast also considering it has no intermediate byte code. But execution speed is never enough so my first thought (when I restart programming at the next version) is speed.
As far as we go on using thinBasic, scripts complexity is increasing. If at first we used thinBasic to create just few lines script and have fun, we are now using thinBasic to make big loops (images or 3D worlds handling), big data handling (we use at work to automate DB tasks an data conversions). In general I see a trend in having scripts more complex than it was before. At the end, more complexity means more code to be executed or the same code executed much more times. All this needs speed and a faster thinBasic Core engine.
I do not want to transform thinBasic into a compiler to have more speed, this mainly for 2 reasons:
I do not have enough capacity, in terms of knowledge and time, to develop a compiler. While I could study more to cover my compiler ignorance, I cannot buy more time at the shop ;)
I love the freedom an interpreted language leave to the programmers and the easy to develop new features and user requests/suggestions.
Back to speed. After version 1.7.7.0 I was checking where, during a script execution, thinBasic was loosing time and I have discovered that most of the execution time is lost during script function execution. And what surprised me was that time is not lost during function code execution but during initial function setup and release. So, in few words, time is mainly lost in allocating memory to adjust variables (local stack used to store local variables and function parameters) and when function execution ends its life (time to take to de-allocate the just created local stack).
What thinBasic Core is doing in the initial and final stage of a script function execution is quite complex and involves the creation of many dynamic structures all connected by pointer in many nested levels. I was thinking on how to avoid all those many allocations every time a function is executed considering that the first time a function is executed I have all the pieces of the puzzle so I could think of a way to do such a time consuming steps only the very first time a function is executed. At the end, instead of releasing all the memory I need to reset used memory.
The biggest problem I can think about is when a user function is executed recursively. In this case I need to allocate further local stack levels for every recursive function execution and release them at the end.
I already started to work on this strategical change and I have to say that initial results are very very promising: around 80% execution speed improvement but I didn’t apply all the optimizations I have in mind.
But I also have a lot of GPF to fix :D Honestly I expected those GPF because this change touch many lines of code and complex memory structures. So my next “week thinBasic time” will be dedicated to this.
Ciao
Eros