> 
> -> generate better byte code, the reflective read is of course slow.


this is easy. What we need to do is to override #emitValue: and #emitStore:

emitValue: methodBuilder

                methodBuilder
                        pushInstVar: baseSlot index;
                        pushLiteral: self name;
                        pushLiteral: nil;
                        send: #at:ifAbsent:
        
for storing, the problem is that the value to be saved is on top of the stack. 
so
we need to first save it and pop it off to be able to use #at:put::

emitStore: methodBuilder
        | tempName |

        tempName := ('0generated_',self name) asSymbol.

        methodBuilder
                addTemp: tempName;
                storeTemp: tempName;
                popTop;
                pushInstVar: baseSlot index;
                pushLiteral: self name;
                pushTemp: tempName;
                send: #at:put:


if we do that and recompile the accessors, we get:


[(TT new tt: 1) tt] bench  

none: "'408,000 per second.'"
+ bc for write slot: "'455,000 per second.'"
+ bc for read: "'487,000 per second.'"

(most of the time is spend in dictionary access, of course)


        Marcus

Reply via email to