There is a method in SourceFileArray #localProcessReadStreamAtFileIndex:atPosition:ifPresent:ifAbsent: which uses a ProccessLocalVariable called
ProccessAndSessionLocalSourcesFileArray (see #localProcessReadOnlyCopy). Changing the last line in #readStreamAt:ifPresent:ifAbsent: to use this local process one makes the time to run this snippet:
[ 1 systemNavigation browseMethodsWithSourceString: 'Morph' matchCase: false ] timeProfile
From ~ 10 seconds to ~ 3 seconds (Windows).
However I cannot see that the file handles created by this processLocalVariable to ever be closed, so I suspect those are leaked? In that case there
might be the need to implement some ���clean up��� mechanism for ProccessLocalVariables before they are changed/nilled when a process changes.
Another approach could be to not use a ProccessLocalVariabe at all, but extend the SourceFilesArray class to also hold one read only handle for each
of its files, and use these in readStreamAtFileIndex:::��� . I guess that it is also necessary then to have semaphore protecting the two last lines such that setting the position in the stream and reading from it cannot be changed by other threads.
readStreamAtFileIndex: index atPosition: position ifPresent: presentBlock ifAbsent: absentBlock
| stream result|
stream := self readOnlyFileAt: index.
stream ifNil: [ ^ absentBlock value ]. "sources file not available"
position > stream size ifTrue: [ ^ absentBlock value ].
readSema critical: [
stream position: position.
result := presentBlock value: stream
].
^ result
Best regards,
Henrik
From: Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org]
On Behalf Of Nicolai Hess
Sent: Thursday, May 19, 2016 9:31 AM
To: Pharo Development List <pharo-dev@lists.pharo.org>
Subject: Re: [Pharo-dev] From a mooc user: method source with it' take so long in Pharo 5
Squeak caches the opened readonly file(handle). It does not have to reopen the file on every call for reading (readonly).
2016-05-18 19:12 GMT+02:00 stepharo <stepharo@free.fr>:
I am wondering why does the search 'method source with it' take so long in Pharo 5? On my PC, When I select the text 'menu' and search for all 'method source with it', in Squeak 5 it takes 3 seconds. In Pharo 5 it takes 21 seconds.