How can I do memoization in Pharo? I mean, a generic mechanism that will help me wrap the caching around the method invocations / messages. I have expensive calls that do not have to refresh their results as often as they are called. TIA Phil |
What's wrong with?
myData ^ data ifNil: [data := self computeMe] Le 03/11/2014 16:10, [hidden email] a écrit : > How can I do memoization in Pharo? > > I mean, a generic mechanism that will help me wrap the caching around > the method invocations / messages. > > I have expensive calls that do not have to refresh their results as > often as they are called. > > TIA > Phil -- Dr. Geo - http://drgeo.eu iStoa - http://istoa.drgeo.eu |
That I do have a lot of places like this and do not want these data littering the code. Aspects would solve this but we do not have that. Also I need the mechanism to be removable. So, I read something about MethodWrapper, ghost, slots... Can't one use any of these things to do this memoization cleanly? Phil > |
Ghost won't be a big help here. Slots would be a good solution but not if it needs to be removable on runtime. So it seems MethodWrappers is your best bet. I'd try create a caching MethodWrapper, mark all the needed methods with a pragma and then install the MethodWrapper on these. Could be a package wide install/uninstall if you need that. Norbert
|
In reply to this post by philippeback
mutate a literal array ? :D
On 3 November 2014 16:10, [hidden email] <[hidden email]> wrote: > How can I do memoization in Pharo? > > I mean, a generic mechanism that will help me wrap the caching around the > method invocations / messages. > > I have expensive calls that do not have to refresh their results as often as > they are called. > > TIA > Phil |
In reply to this post by NorbertHartl
On Tue, Nov 4, 2014 at 9:59 AM, Norbert Hartl <[hidden email]> wrote:
I loaded MethodWrappers in 3.0 as I saw in http://forum.world.st/MethodWrappers-td3829576.html#a4601624 Gofer it squeaksource: 'MethodWrappers'; package: 'MethodWrappers4'; load. It loads. But no test seems to be fine. What version should I be using? Phil
|
I'm not sure. I thought Spy would use them but it does not load in a fresh pharo3 for me. Did you try
? Norbert
|
On Tue, Nov 4, 2014 at 12:06 PM, Norbert Hartl <[hidden email]> wrote:
This one loads and tests are green once the "_"s are replaced with ":="s Thx for the pointer. I'll see how I can hook a TTLCache into this. Phil
|
In reply to this post by NorbertHartl
This would be a nice useless for Reflectivity… one way of describing it is “like method wrappers, but generalized”. e.g. you can put a “wrapper” on any kind of AST node. After the breakpoints, we could use that as the next client. Marcus
|
Sure, I forgot. If I would have the need to implement it I would try solving it with meta-links. Basically it does the same as the method wrapper without having the need to exchange the compiled method. Norbert
|
In reply to this post by Marcus Denker-4
2014-11-04 13:16 GMT+01:00 Marcus Denker <[hidden email]>:
yes Nick's Reflectogram would also be usable for that but it would require a special VM currently. Indeed, it would be better to have at the compiler level. Then, Ghost is also usable for that since Mariano did a MethodWrapper like implementation using Ghost in 5 lines or so. And Ghost should load in Pharo 3 ;-) Luc
|
In reply to this post by philippeback
I don't know your exact use case. But if you need one cache for your package with TTLCache then this could be done in one pass. You can have an installer that scans your package for methods containing a special pragma. Then you exchange every compiled method (installing the wrapper) with the wrapper that accesses its value from the same TTLCache having the compiled method as key. So you would have exchanged a lot of methods that share a single cache. As the TTLCache gives the hit rate on printString you get back an effectivity number for free. Norbert
|
In reply to this post by philippeback
Hi There is AspectS package at old squeaksource site. I not know is it working in Pharo. 04 нояб. 2014 г. 9:04 пользователь "[hidden email]" <[hidden email]> написал:
|
On Nov 4, 2014, at 1:50 PM, Denis Kudriashov <[hidden email]> wrote:
---> Save our in-boxes! http://emailcharter.org <---
Johan Fabry - http://pleiad.cl/~jfabry PLEIAD lab - Computer Science Department (DCC) - University of Chile |
2014-11-04 16:09 GMT+03:00 Johan Fabry <[hidden email]>:
Exactly |
In reply to this post by jfabry
I have been reading on Ghost: This link is dead BTW:http://rmod.inria.fr/web/pier/software/Marea/GhostProxies I found a version here: http://www.smalltalkhub.com/#!/~CAR/Ghost/ It isn't in the ConfigurationBrowser, so I wonder where is the version to use. Phil On Tue, Nov 4, 2014 at 2:09 PM, Johan Fabry <[hidden email]> wrote:
|
Hi Phil,
Ok I missed the details so I've just refreshed my mind. yes the latest repository is this one: http://www.smalltalkhub.com/#!/~CAR/Ghost/ I've just tried in Pharo 3.0 and it works now (yes oups I forgot that it was for Pharo 2.0 ;-)). Ghost is really small so I've just fixed it Try it: ConfigurationOfGhost load Tests are green for me. No I did not push the config in the right place to have it in the ConfigurationBrowser. You can find infos+examples on how to achieve Method wrapper in Mariano's PhD (p116) using Proxies for Methods.
and also look at the test case method named #testSimpleForwardingForMethodUsingBecome Cheers, Luc 2014-11-04 15:48 GMT+01:00 [hidden email] <[hidden email]>:
|
On Tue, Nov 4, 2014 at 4:56 PM, Luc Fabresse <[hidden email]> wrote:
Thanks a lot!
I loaded the configuration: Gofer it smalltalkhubUser: 'CAR' project: 'Ghost'; package: 'ConfigurationOfGhost'; load. (#ConfigurationOfGhost asClass project version: #stable) load. Tests are all green.
I've put it in the Metarepo for 3.0
I didn't had that one, thanks!
Yes, seen that.
Much appreciated! Ghost is quite nice and useful. Could do with some more class comments as there is none. I'll try to put in some as I use it. Phil
|
In reply to this post by Luc Fabresse
Luc, Can you add me to the repo so that I can send updates? Phil On Tue, Nov 4, 2014 at 4:56 PM, Luc Fabresse <[hidden email]> wrote:
|
just added you as a contributor. And yes comments are more than welcome ;-) #Luc 2014-11-04 18:03 GMT+01:00 [hidden email] <[hidden email]>:
|
Free forum by Nabble | Edit this page |