Keeping several versions around

Niko Schwarz niko.schwarz at googlemail.com
Thu Jul 30 11:53:02 UTC 2009


Hi!

I am interested in keeping several versions of code living side by
side in the same image. There is an implementation in Smalltalk, but
I'd like to know if this could be done more elegantly using Self.

The Smalltalk implementation is called Changeboxes,
http://scg.unibe.ch/archive/papers/Denk07cChangeboxes.pdf. It
essentially works by hooking into the compiler and then, upon every
method compilation, NOT pushing the Class onto the stack, but rather a
level of indirection which finds the correct version of the class.

The idea is essentially the following. Imagine you just built a
feature, and it works, let's say you just implemented Exponentiation
using a while loop, that just multiplies a number with itself a given
number of times. It works. But you find it slow. Now, you fork, and
keep the old version around. You change the method, right there, you
don't make a new method, you CHANGE the old one. But still, you keep
the old one around.

And then you run them side by side. The currently active branch might
be the sped up algorithm, but you can still access the main trunk, so
now you benchmark the two, and see if they yield the same results:

[2 raisedTo: 100 ] timeToRunAndResult
[[2 raisedTo:100] inBranch: #main] timeToRunAndResult

So, how would you implement this version change with only little
performance penalty? How does the lookup process work anyway and how
can I hook into it?

All the best,

Niko

raisedToThe: anInteger
|res|
res := 1.
anInteger timesRepeat: [ res = res * self]
^

 but it is slow. Now you fork, and keep the working version around,
both for examination



More information about the Self-interest mailing list