On 06/29/2011 12:07 AM, Holger Hans Peter Freyther wrote:
>  -  amortize their execution times.  The default implementation
>  -  does nothing, so it is optimized out by the virtual machine
>  -  and so it loses very little on the performance side.  Note
>  -  that descendants of Collection have to call it explicitly
>  -  since #do: is abstract in Collection."
>  -
so this was not true about the VM/compiler? Was it true at some point?

It is true, but Gwen is looking at microoptimization. Also, originally I was thinking of adding it only on top of O(n) or worse operations, but this is not so since it's also in #first, #last, #at: etc. So, #beConsistent imposes a fixed cost on frequently-read OrderedCollections.

In other words, with something like

-       self beConsistent.
        ^lastIndex >= firstIndex
            ifTrue: [self basicAt: lastIndex]
            ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self
                      withIndex: 0]

where you have four method calls (#at: itself and three primitives: #beConsistent, #>=, #basicAt:), the single call to #beConsistent can easily cost 5-10% or perhaps more.

Paolo

_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to