Raphael Collet wrote:
> Filip Konvička wrote:
>
>> I wanted to measure the performance of the comparison operator
>> Value.'==', and I do not understand the results I get.
>
> (...)
>
>> Results:
>> T1==T2 finished in 687 ms
>> T1==T2 (2) finished in 688 ms
>> T1==T3 finished in 78 ms
>>
>> TEST1 and TEST2 perform equally, even though T1 is unified with T2
>> before TEST2. Shouldn't TEST2 be as fast as TEST3?
>
> Unification does not merge data structures in memory! It only performs
> variable bindings to make both values isomorphic.
Hmm. I believe the following optimization is worth considering: when two
variables are either bound together or successfully tested for structural
equality, set both to point to the structure with the lower address.
(Note that this only incurs extra overhead in the slow path where the
full unification or structural equality algorithms are needed, not in the
fast paths where they either already have the same address, or one was
unbound.)
The main advantage is for memory usage -- it tends to reduce the number of
copies of identical structures, as the ones that are no longer referenced
are garbage collected. I don't remember where I first heard about this idea
(maybe on the C2 wiki?), but some Lisp implementations used it, I think.
> Therefore T1=T2 has
> no effect on memory, it only checks equality. T3=T1 is different: it
> binds T3 to the record T1, making T1 and T3 identical references.
>
> You can observe the difference with System.eq, which returns true if
> both arguments are identical references. {System.eq T1 T2} returns
> false, while {System.eq T1 T3} returns true.
Is System.eq supposed to be guaranteed to distinguish between structurally
equal values that have been bound together? If so then this would prevent
the above optimization -- but perhaps its specification is too strong in
that case.
--
David Hopwood <[EMAIL PROTECTED]>
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users