Yes! Worth to note, this also includes blocks and thisContext.

And some others:

- cache results of common operations (e.g., using WeakIdentityKeyDictionary or MRUCache)
- pooling: reuse objects instead of throwing them away to reduce GC load

For multiprocessing:

- run multiple network/OSProcess requests concurrently
- to avoid frame rate drops, send Processor yield with a high frequency in long-running background operations (it only costs a couple of nanoseconds, which is as much as 2 regular message sends)

Von: Chris Muller <asqueaker@gmail.com>
Gesendet: Donnerstag, 11. Januar 2024 00:10 Uhr
An: The general-purpose Squeak developers list <squeak-dev@lists.squeakfoundation.org>
Betreff: [squeak-dev] Re: Do we have a catalogue of best practices for writing efficient Squeak code?
 
Minimize creation of temporary objects.

On Wed, Jan 10, 2024 at 2:01 PM <christoph.thiede@student.hpi.uni-potsdam.de> wrote:
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