[ENH] Ten Percent Faster Morphic!

Ned Konz ned at whidbey.net
Sat Jan 28 03:57:01 UTC 2012


These two change sets together offer an improvement in the 10% range for
typical Morphic construction and drawing.

The biggest improvement comes from changing Morph property dictionaries
from IdentityDictionary to OrderedCollection and using an unrolled loop
to scan for properties.

Something like 95% of all Morphs that have properties have four or less;
this code takes advantage of this fact.

The second change speeds up rectangle invalidation by a little bit by
being more efficient at looking up the wonderlandTexture property. This
trades space for speed by making the wonderlandTexture property an
instance variable of MorphExtension. However, the total memory hit is
only about 32K in a stock image, and the first change set saves at least
that much.

On Dan's test (lots of browsers opening), I got a 7% improvement out of
the properties dictionary change, and another 1.9% improvement for the
invalidRect: optimization, for a total of 8.7% improvement.

On Andreas' test (lots of menus opening), I got a 12.3% improvement out
of the properties dictionary change, and another 2% improvement for the
invalidRect: optimization, for a total of 14.1% improvement.

I have enclosed the benchmark programs as well (select them and do a
"print it") so you can see how much improvement you get.

from preamble:

"Change Set:		FasterProperties-nk
Date:			3 August 2002
Author:			Ned Konz

Currently, Morphs can have properties added and removed dynamically.
Their properties are stored in IdentityDictionaries in the Morph
extensions.
These property dictionaries are typically very small (95% have 4 or less
entries; none has more than 8).
Because of this, using linear searches in OrderedCollections is
considerably faster.

This change set modifies Morph to use OrderedCollections instead of
IdentityDictionaries to hold properties. It will also work with old
Morphs that use IdentityDictionaries; no conversion of Projects, etc. is
necessary.

The postscript will convert all existing property dictionaries in
MorphExtensions into OrderedCollections.

However, Morphs loaded in with projects will continue to use the
IdentityDictionaries.

There is a utility method you can run if you want to convert Morphs
loaded in from projects:

Morph convertPropertyDictionariesToOrderedCollections

In two tests (Dan's browser opening tests and Andreas' menu opening
tests), I got 7% and 12.3% improvement (respectively) from this change
set.
"!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FasterProperties-nk.cs.gz
Type: application/octet-stream
Size: 4441 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20120128/7d4046da/FasterProperties-nk.cs.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InvRectOpt-nk.2.cs.gz
Type: application/octet-stream
Size: 1544 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20120128/7d4046da/InvRectOpt-nk.2.cs.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Benchmarks.text.gz
Type: application/octet-stream
Size: 642 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20120128/7d4046da/Benchmarks.text.obj


More information about the Squeak-dev mailing list