Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!delmarva.com!newsfeed.internetmci.com!howland.reston.ans.net!torn!nott!cunews!dbuck
From: dbuck@superior.carleton.ca (Dave Buck)
Subject: Re: Smalltalk vs C vs C++ benchmark results [Fortran]
X-Nntp-Posting-Host: superior.carleton.ca
Message-ID: <DEw6yJ.CJx@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University, Ottawa, Canada
References: <DEDsF1.3I8@cunews.carleton.ca> <437aad$h1f@news.iastate.edu> <NEWTNews.811030751.8797.sellers@sellers.sellers.com> <438a9a$s0v@news.iastate.edu>
Date: Thu, 14 Sep 1995 11:08:43 GMT
Lines: 51

In article <438a9a$s0v@news.iastate.edu>,
Rick Hawkins <rhawkins@iastate.edu> wrote:
>I'm only now seeing ways that i might cut down on the
>calls.  I'd sure like an operator, though, that would do a direct
>integer addition.  eg, rather than proccessing the message myNum :=
>myNum + 8, which, as i understand it, will send a message + 8 to mynum,
>which will return a value, I would like to see a int+ operator that will
>assume that myNum holds an integer and increment the word at the address
>pointed to by mnNum by 8.

The commercial Smalltalks have an optimization for this purpose.  For
the heavily used math operations, they try to inline the operation
with a quick type check of the parameters.  If both parameters are
SmallIntegers, then no method lookup or invokation is performed.
Instead, the operation is performed by the calling method.  Similar
optimizations exist for many other low-level operations (like Array
at:put:) to make the as fast as possible in the normal case.

Also, commercial Smalltalks have optimizations for methods which only
do simple things (return self, return a constant, return an instance
variable, set an instance variable, etc.)  The method lookup is
performed as usual but once the method is found, a flag in the method
indicates that it's a "simple" method.  A method invokation isn't
performed and instead the operation is performed from the sender's
context.

There are other optimizations which are performed as well, but these
would seem to have a major impact on your performance.  The bottom
line is that in Smalltalk, not all operations are done literally as
they appear in the source code.  The ifTrue: and ifFalse: messages are
normally not messages and instead compile to tests and branches.  We
only think of it as a message conceptually.

>  I was also ready to kill for BASIC's "Print
>Using" statement.  [YEs, i realize that the first adds static typing,
>and the second creates some kind of global object which would take
>non-standard messages (though not all that far:  Print could be the
>object, using the message, and the , could label each extra argument
>rather than a comma:)]

VisualWorks has a PrintConverter object for this purpose. It takes a
number and a string as parameters and does the formatting for you.

David Buck
dbuck@ccs.carleton.ca

_________________________________
| David K. Buck                 |
| dbuck@ccs.carleton.ca         |
| The Object People             |
|_______________________________|
