As I can understand, in stateful contracts state is represented with key-value pairs and for storing a variable, the name of that variable would be the “key” and the pair would be stored in the state. This official example from developer docs shows this:
int 0
byte "MyLocalKey"
int 50
app_local_put
This is really an inefficient method. With this method the name of variables will be stored in the state too. In a map data structure always a copy of keys need to be stored in the memory. For example, if the map data structure is implemented using a hash table, the keys need to be stored to be able to detect hash collisions.
The point is, Algorand’s VM should have a random access memory like all other conventional machines (besides its stack). The data should be stored and loaded using addresses and the mapping between names of variables and their address can be done in compiler/assembler using symbol tables. There is no need for storing names in the memory.
In other words, state data in a contract should be represented by an array and not a map (key-value pair). and programmer will be responsible for remembering the index of his variables. (actually compiler will do this). The code would be something like this:
define my_var
int 0
int my_var //assembler will replace my_var with its index/address
int 50
app_local_put