The topic of namespaces in Cincom Smalltalk (this now applies to both VisualWorks and ObjectStudio) has come up again. A new blog popped up recently, about the alleged faults of Seaside. Now, I'm not going to claim that Seaside is a perfect web framework - no large body of work is ever perfect, and Seaside, like any such work, has warts. Overall, I think it's a great system, which is why I pushed to have Cincom start supporting it in our Smalltalk products. When you follow the link through though, be aware - while you'll find a few good suggestions, it's hard to keep them in mind given the general level of anger and obnoxiousness on display.
Anyway
A few days ago, this post was made on namespaces in VW, with this assertion:
In VisualWorks accessing classes by their namespaces bindings is very slow!
Certainly that used to be the case; if you go back to the 5i releases, and I think the early 7.x releases, resolving dotted namespaces could be slow. That hasn't been the case for awhile though. Here's a small test I put together, with two classes:
Smalltalk.MySpace defineClass: #MyTester
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: 'value '
classInstanceVariableNames: ''
imports: ''
category: ''
Smalltalk defineClass: #MyTester2
superclass: #{Core.Object}
indexedType: #none
private: false
instanceVariableNames: 'value '
classInstanceVariableNames: ''
imports: ''
category: ''
I gave them both the same "doWork" method, which takes awhile to run:
value := 10000 factorial
Then, I used another class (in the Smalltalk namespace) to run this test:
| val1 val2 |
MySpace.MyTester new doWork.
MyTester2 new doWork.
val1 := Time millisecondsToRun: [100 timesRepeat: [MySpace.MyTester new doWork]].
val2 := Time millisecondsToRun: [100 timesRepeat: [MyTester2 new doWork]].
Transcript show: 'With namespace: ', val1 printString; cr.
Transcript show: 'Without namespace: ', val2 printString; cr.
What were the results? The time to run the test using the dotted namespace notation (in milliseconds): 54535. Running the same test without the dotted lookup: 54643.
That's a small enough difference that I can't draw any conclusion beyond this: dotted namespace lookups aren't actually slow, and it makes a lot of sense to use namespaces when working in a Smalltalk dialect that has them - it makes for simpler naming conventions.
This shouldn't be construed as meaning that I want to see the Seaside core team push for namespaces in Squeak and start using them; that's up to them, and I don't really have an opinion on that. My sole point here is to knock down the assertion that namespace lookups in VisualWorks (or ObjectStudio) are slow. They aren't.
Technorati Tags:
namespaces, visualworks, objectstudio