[Vm-dev] Re: SmallInetger as methods was not ready yet....now
maybe?
Eliot Miranda
eliot.miranda at gmail.com
Sat Dec 4 04:08:53 UTC 2010
On Fri, Dec 3, 2010 at 5:21 PM, Andreas Raab <andreas.raab at gmx.de> wrote:
>
> On 12/3/2010 4:18 PM, Eliot Miranda wrote:
>
>> BTW, Mariano's use of SmallIntegers rather than wrappers is an attempt
>> to get a very compact image and seems a reasonable experiment. Using
>> wrappers would defeat his use-as-little-memory-as-possible purpose.
>>
>
> Not at all. The design of objects-as-methods was deliberately done such
> that one could use a single wrapper for multiple methods. The only thing you
> need is to map from selector to method being executed. For example:
>
> MethodSwapper>>run: aSelector with: argsArray in: aReceiver
> "Execute the given method"
> method:= methodMap at: aSelector.
> ^aReceiver withArgs: argsArray executeMethod: method
>
>
Ah, much nicer.
> Then you install a single MethodSwapper instance like here:
>
> swapper := MethodSwapper new.
> Morph selectorsAndMethodsDo:[:sel :meth| swapper methodMap at: sel put:
> meth].
> Morph selectorsDo:[:sel| Morph addSelector: sel withMethod: swapper].
>
> At this point the only overhead you have is what's in the (single)
> MethodSwapper instance and even with a most naive implementation (looking up
> the index by selector) you'd have 8 bytes per method in your image which I
> suspect is well below 5% of the image size.
>
> And then of course you can start *really* looking at getting the size down.
> Did you know that Dan once did a very neat hack where he replaced all
> symbols with integers? Works great and if you do that you not only reclaim
> the space for the symbols but also don't need a lookup at all :-)
>
I didn't know that Dan had done this. ActiveBook did this with the
Smalltalk running on my BrouHaHa VM. All the Smalltalk VMs I've worked on
have supported immediate selectors, and a good thing too :)
best
Eliot
> Cheers,
> - Andreas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20101203/eb6a0363/attachment.htm
More information about the Vm-dev
mailing list