Some things that come to my mind for optimizing your Smalltalk code:
* use MessageTally (tally it, #timeProfile, profiler in docking bar) to find bottlenecks w.r.t. speed
* use #timeToRun or #bench[For:] to benchmark expressions
* inline frequently executed methods (inspect the bytecode, avoid sending messages that are not inlined)
* use quick return methods
* avoid slow instructions (e.g., thisContext or repeated block closure creations)
* be aware of slow primitives (e.g., #becomeForward: is pretty slow while #elementsForwardIdentityTo: is faster for bulk mutations)
* use SpaceTally to find bottlenecks w.r.t. memory consumption
* for collections of homogenous objects, use RawBitsArrays when available (as they optimize memory consumption and operations, e.g., thanks to the FloatArrayPlugin)
* know the object layout in the VM (e.g., in the OSVM you get one instance variable for free)
* avoid eager optimization
Surely this list is not comprehensive. But I was wondering, is there already a community document where we can collect and refine such tricks and insights? If not, what would be the right form for it? A wiki page, a chapter or book in the help browser, something else? And what would you add to this list? :-)
Best,
Christoph
---
Sent from Squeak Inbox Talk