[Gambas-user] Problems with interpreter optimization and CPU behaviour

Benoit Minisini benoit.minisini at gambas-basic.org
Sat Oct 8 19:33:02 CEST 2022


Just an informative mail about the current interpreter optimizations, 
and the problem I encounter.

I have just added a new bytecode for implementing the different memory 
write instructions : 'Byte@(ptr) = value', 'Int@(ptr) = value', and so on.

The interpreter loop is a big switch based on a big jump table (one by 
bytecode, they are 256).

Adding the new bytecode is just adding a new "goto" target destination, 
a call to the function that implements the new instructions, and another 
'goto' instruction to move to the next bytecode.

Something like that:


	SUBR_poke(code); // 'code' is the bytecode being interpreted
	goto _NEXT;

If I test the 'mandelbrot.gbs' benchmark, its execution time becomes 
150% slower when I just add these three lines of C code!

I have no idea why. At the moment, I think that the size of the 
interpreter loop pass some sort of cache limit somewhere that trashes 
the CPU performances. But all that seems random to me, and makes 
optimizing vey difficult!

If someone has any idea, he's welcome!

Benoît Minisini.

More information about the User mailing list