[Chicago-talk] neat little optimization

Greg Fast gdf at speakeasy.net
Thu Oct 14 07:34:41 CDT 2004

On Wed, 13 Oct 2004 21:24:34 -0500, Komtanoo Pinpimai <komtanoo at gmail.com> wrote:
> I think I had seen someone mentioned that the memoization will be
> embeded in Perl6, called fly weight pattern.
> In the fly weight pattern when you call a function, the compiler
> record you function call and all the operators.

Memoization is one way of implementing flyweight, when the memoized
functions return cachable objects.

The flyweight pattern is just this: when you have a significant number
of indistinguishable things ("objects"), try to use references to a
single shared thing.

So for example, you can memoize the call to new() for some class, and
then every time a user creates an instance of that object with the
same params as one that's been created before, new() will return the
first object it created.

This can get you not only a speed win (you don't have to initialize a
new object every time, like the other memoization examples in this
thread), but also saves space...  if used in the right situation.

Greg Fast

More information about the Chicago-talk mailing list