Hello Mansour
>> "Thank you for letting Ring be better at this front."
You are welcome :D
>> "For the sake if discovery, I am wandering what you made to get this performance gain in calling objets methods..."
In general, there are common & known ideas to improve the performance like
(1) Avoiding unnecessary instructions.
(2) Caching results
(3) Reducing abstractions
(4) Reducing memory
(5) Using arrays instead of linked lists
(6) Replacing VM instructions with optimized instructions that uses cached results
(7) Using VM instruction that does multiple things (Super Instructions)
When we use object.method()
At first, Ring VM access the object through multiple steps
* Access a List the represent the Ring variable and exist in a specific scope
* Access a List that represent the object (Class pointer, Object Data)
* Use the class pointer to get the class methods (taking inheritance in mind)
* Search in the methods for the method that we want using HashTable
* Get the (this) variable list from internal global scope and update it according to the current object
* Call the method
* These operations are multiple VM instructions that are executed by the bytecode execution loop
So, we did the next optimizations
(1) Defining a new preprocessor that access the variable list directly (without using functions that check the list size, item type, etc.) - Then using this preprocessor in each place in Ring VM source code that access a variable list
(2) Defining a new preprocessor that access the object list direction (without using functions that check the list size, item type, etc.) - Then using this preprocessor in each place in Ring VM source code that access the object list
(3) When finding a method, cache the result in the current byte code instruction and change the instruction operation code to another one that uses the cache (if it's valid) directly
(4) Instead of searching for the (this) variable list - cache it in the VM structure
(5) Replace the switch statement in bytecode execution loop with computed goto
(6) When calling a method, we used to store the current object data in a Ring list pObjState - and we used to add/delete sub lists to this list when we use objects. We changed this behavior to use pre-allocated array and just increment/decrement a counter
Greetings,
Mahmoud