Chris thanks for your answers. Yes, I was using the release 39. I´ve tested it with r40 (r40Gamma3) and it worked better.
I tested this with a bigger collection (84661 objects ) and it takes 16 seconds to answer either #size and #lastKnownSize. Do I have to set something to enable #lastKnownSize caching?
 
The new results are:
"------------ 84661 objects - MagmaCollection>>size - fiirst evaluation"
[ (magmaSession root at: #ThesaurusTerm) size ] timeToRun  "answer about  247 milliseconds"
"Note: magmaSession root at: #ThesaurusTerm answer a MagmaCollection"
 
"second evaluation"
[ (magmaSession root at: #ThesaurusTerm) size ] timeToRun  "answer about 0 milliseconds"
 
"MagmaCollectionReader>>size  first evaluation"
[ ((magmaSession root at: #ThesaurusTerm) read: #issnString) size ] timeToRun "answer about   16771 milliseconds"
"second evaluation"
[ ((magmaSession root at: #ThesaurusTerm) read: #issnString) size ] timeToRun "answer about    16870 milliseconds"
 
"MagmaCollectionReader>>size  first evaluation"
[ ((magmaSession root at: #ThesaurusTerm) read: #issnString) lastKnownSize] timeToRun "answer about    16573 milliseconds"
"second evaluation"
[ ((magmaSession root at: #ThesaurusTerm) read: #issnString) lastKnownSize] timeToRun "answer about     16529 milliseconds"
 
 
"------- 5500 objects - MagmaCollection>>size - fiirst evaluation"
[ (magmaSession root at: #Serial) size ] timeToRun  "answer about 698 milliseconds"
"Note: magmaSession root at: #Serial answer a MagmaCollection"
 
"second evaluation"
[ (magmaSession root at: #Serial) size ] timeToRun  "answer about 0 milliseconds"
 
"MagmaCollectionReader>>size  first evaluation"
[ ((magmaSession root at: #Serial) read: #issnString) size ] timeToRun "answer about  1246 milliseconds"
"second evaluation"
[ ((magmaSession root at: #Serial) read: #issnString) size ] timeToRun "answer about   1246 milliseconds"

Juan M.
 
On 8/31/07, Chris Muller <asqueaker@gmail.com > wrote:
Juan, please the section "Optimizing Performance" in the documentation
about querying MagmaCollections to understand when #size will be very
fast vs. pretty slow.

http://wiki.squeak.org/squeak/5859

For the cases that are "pretty slow" ( i.e., a Reader requiring
distinct results), note you have #lastKnownSize, which is the cached
size (therefore instant access).

- Chris