[Pharo-project] Speeding up Finder string search
smalltalk at stefan-marr.de
Mon Jan 16 22:07:22 CET 2012
On 16 Jan 2012, at 14:50, Stefan Marr wrote:
> On 16 Jan 2012, at 14:31, Camillo Bruni wrote:
>> I guess having the sources completely in the image is the straight-forward solution to this :/
> Well, we could also cache just the resulting source string.
> Not sure what that means in terms of memory, but going to the file every time a method is asked for its code seems to be very naive.
I put a cache (IdentityDictionary) methodSource into Class. That requires recompiling all classes which takes a while, and I do not know, whether it should not be in ClassDescription.
And guess what:
The bad news: the image size doubles from 22.2MB to 39.5MB.
The good news:
"before using cache" #(43239 23490 22084) #(20581 20238 20207)
The 43239 created all dictionaries.
"warming up and using cache"
#(20177 1428 1393) #(1389 1374 1400)
That is a pretty nice speedup, grep is still a faster, but now finder becomes usable!
I use the cache like this:
"Read the source code from file, determining source file index and
file position from the last 3 bytes of this method."
| position classSrc |
classSrc := self methodClass getSourceFor: self selector.
classSrc ifNotNil: [
(position := self filePosition) = 0 ifTrue: [^ nil].
classSrc := (RemoteString newFileNumber: self fileIndex position: position) string.
self methodClass setSourceFor: self selector to: classSrc.
To me that feels all pretty straight forward and naive, so feel free to have better ideas.
Perhaps the cache should get evicted when not used, etc...
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
Phone: +32 2 629 2974
Fax: +32 2 629 3525
More information about the Pharo-project