[Chicago-talk] neat little optimization
jt at plainblack.com
Thu Oct 14 09:42:34 CDT 2004
Ok, everybody is talking this up, but there must be a down side. Is Memoize storing all
of these cached objects in memory, or out to disk? Let's say I wanted to use it in a
mod_perl app, on an class that has 2 million object instances that may be called. If
this is persisted in memory, I can see that eating through memory very quickly.
Can anybody speak to the do's and don'ts of this thing?
On Thu, 14 Oct 2004 07:34:41 -0500
Greg Fast <gdf at speakeasy.net> wrote:
>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.
>Chicago-talk mailing list
>Chicago-talk at mail.pm.org
JT ~ Plain Black
Create like a god, command like a king, work like a slave.
More information about the Chicago-talk