Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!uhog.mit.edu!bloom-beacon.mit.edu!world!jhaungs
From: jhaungs@world.std.com (Jim Haungs)
Subject: Re: Sorting fix in ST80
Message-ID: <D8zMzq.L6u@world.std.com>
Organization: The World Public Access UNIX, Brookline, MA
References: <3pq9fe$86b@news.hboc.com>
Date: Mon, 22 May 1995 16:26:14 GMT
Lines: 35

alan_ro@hboc.com (Alan Rouse) writes:

>I recently read an article comparing performance benchmarks for 
>VisualWorks, Visual Smalltalk, and Visual Age. The article said that the 
>sorting algorithm used in ParcPlace's SortedCollection contained a 
>logical error that resulted in slow sorting.  The article gave a simple 
>fix that supposedly would make a dramatic improvement in sorting speeds.

>Unfortunately, I cannot locate the article....

>Can anyone help me with either (a) the source of the article I'm 
>describing, or better yet, (b) the sorting fix?

>Thanks!

It's not really a logic error, it's polymorphism.  The comparison
of two elements during a sort is done with the #<= operator, which
can't/won't determine a priori if two objects are of the same
type.  

I was the person who posted the comparative benchmarks on 
comp.lang.smalltalk, and ParcPlace's response indicated that if 
you knew the types, and/or knew the collection was homogeneous,
you could use a different sortblock to speed up the sort.  For
example, if you knew the collection contained only strings,
you could write the sortBlock as: [:a :b | (a trueCompare: b) < 0].
The trueCompare: method returns -1 if the lexical comparison is 
a <= b, and assumes that both operands are Strings.  

I tried this and it radically sped up the sort.  You can use this 
trick on any homogenous collection by writing your own 
trueCompare: (or equivalent) method for objects of that class.

Jim

