[mercury-users] version_array vs. field update performance

Ralph Becket rafe at csse.unimelb.edu.au
Wed Feb 7 11:13:24 AEDT 2007

Ondrej Bojar, Tuesday,  6 February 2007:
> Hi,
> I'm working with many vectors of floats, all of a fixed length. I create 
> lots of them, then stepwise set and update some of the fields and sort 
> them according to a scalar product with a constant "weights" vector.
> Currently I use version_array to store each vector.
> About 7% of run time is used on 'version_array.elem :=', and another 6% 
> is used on 'version_array.elem'.

Are you using unsafe_rewind after backtracking?  If you aren't then
every version_array access is paying a cost for any updates on previous
search paths.

Also, unless you're working on a 64 bit machine, floats are normally
boxed which has a significant impact of FP intensive programs.  You can
try using --single-precision-floats if you like if you have a very
recent version of the compiler (I think Peter Wang checked this in the
other day - check the reviews mailing list archive for this month to be

> Given that the vector length is fixed, I could use tuples or data terms 
> with field access functions to get or update vector components.

It's hard to imagine tuple updates beating version arrays unless they
are very small (under ten or twenty fields would be my guess).

> In a small test, I tried to compared the performance of each of the 
> representations and I was surprised to see that there is nearly no speed 
> difference observable. Would this be what you expect?

Yes: a version array update allocates a four word heap cell to record
the overwritten contents and then does an in-place update of the array;
a tuple update has to copy the entire tuple.

> I was hoping to see there is less overhead in the field update
> routines.
> Can arrays (with the di/uo workaround hassle) be faster?

Arrays are about 1.5 - 3 times faster, but you can't backtrack over

-- Ralph
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list