[squeak-dev] The Inbox: Files-dtl.184.mcz

David T. Lewis lewis at mail.msen.com
Mon Oct 28 12:51:53 UTC 2019


Hi Levente,

On Sun, Oct 27, 2019 at 08:02:13PM +0100, Levente Uzonyi wrote:
> On Sat, 26 Oct 2019, David T. Lewis wrote:
> 
> >From a performance perspective, is it better to avoid using on:do: even
> >if one expects the block to succeed in the common case?
> 
> Yes. The block has to be created, the error handler has to be initialized, 
> even if there will be no error.
> Here's a small benchmark I just came up with:
> 
> ({
> 	[ "Empty code. Result should be subtracted from the other results."
> 		| s |
> 		s := ByteString new: 1.
> 		1 to: 1000000 do: [ :i | ] ] timeToRun.
> 	Smalltalk garbageCollect.
> 	[ "#adoptInstance:"
> 		| s |
> 		s := ByteString new: 1.
> 		1 to: 1000000 do: [ :i |
> 			ByteArray adoptInstance: s.
> 			ByteString adoptInstance: s. ] ] timeToRun.
> 	Smalltalk garbageCollect.
> 	[ "#asByteArray"
> 		| s |
> 		s := ByteString new: 1.
> 		1 to: 1000000 do: [ :i |
> 			s := s asByteArray.
> 			s := s asString ] ] timeToRun.
> 	Smalltalk garbageCollect.
> 	[ "#adoptInstance: with error handler for ByteString -> ByteArray 
> 	conversion"
> 		| s |
> 		s := ByteString new: 1.
> 		1 to: 1000000 do: [ :i |
> 			[ ByteArray adoptInstance: s ] on: Error do: [ s := 
> 			s asByteArray ].
> 			ByteString adoptInstance: s ] ] timeToRun.
> } withIndexCollect: [ :each :index | index odd ifTrue: [ each ] ]) reject: 
> #isNil
> 
> "==> #(2 33 75 76)"
> 

Indeed, that makes it very clear!

> >
> >The #ascii implementation is not a concern. ByteString can adopt an
> >instance of ByteArray on V3.
> 
> Okay, I thought #adoptInstance: was not supported in V3.
> Since it is supported, I presume the problem is that ByteArray is not 
> compact while ByteString is compact. So, if ByteArray were compact, then I 
> think #adoptInstance: would work.
> IIRC more than half of #compactClassesArray is empty, so perhaps the 
> easiest fix is to make ByteArray compact. That should speed up other 
> things as well. It was a while ago I used a V3 image, but I think it's as 
> simple as evaluating [ByteArray becomeCompact].
> 

I just tried your suggesting [ByteArray becomeCompact], and it works
fine. As you say, there is plenty of space in the compact classes array,
and this changes the total number of entries from 13 to 14 in the V3
image.

Thank you for your patient explanations. I moved Files-dtl.184 to the
treated inbox.

Dave



More information about the Squeak-dev mailing list