[xquery-talk] From map entry pairs to a pair of arrays

Christian Grün christian.gruen at gmail.com
Mon Jul 17 03:49:31 PDT 2017


Hi Wouter,

> What I meant is that the cost of immutability can be avoided in some cases.
> That's primarily a matter of low level short-circuiting, not so much of
> writing something new. I don't know if this can be done in Java, I know the
> Clojure compiler does this, and I'm not aware of XQ engines that do
> transient operations on persistent collections.

I see, thanks.

In most cases, I would doubt that it’s the immutability of XQuery maps
that slows down queries. The performance of hash tries (which I assume
are used in most implementations of XQuery) is close to mutable hash
maps. As Michael indicated, if data is repeatedly copied, immutable
maps can outperform classical hash maps, so it can even be a wise
choice to use them deliberately.

I have no idea about transient operations in Clojure. Do you know if
they are they based on a general concept, or are they closely related
to the semantics of Clojure? If they are intransparent for the user,
as it seems, I would assume they are comparable to other internal
optimizations that can be applied on a map (such as e.g. resorting to
intermediary mutable data structures if it is known in advance that a
bulk operation takes place).

It would be interesting to have a closer look at some real queries in
which maps seem to be insufficient, and find out if the bottleneck is
really the immutability of the maps, the usage of maps, or the usage
of XQuery in general.

Christian


> Op 16 jul. 2017 23:58 schreef "Michael Kay" <mike at saxonica.com>:
>
> ce between C and Assembly is a lot smaller than between C and XQ, and I
> think memory management should not be taken lightly (I'm not saying you do).
> In OP's case, I believe keys could be discarded while memory layout remains
> intact.
>
>
> As a general rule of thumb, a lower-level language performs better provided
> that you have the time and skills to write the code efficiently.
>
> And as a general rule of thumb, you don't.
>
> Even when you are quite convinced that you do.
>
> It's a long time since I wrote in anything as low-level as C or assembler,
> but if you compare XQuery and Java, the level of abstraction of the API for
> maps is very similar, so there is no intrinsic reason to believe one should
> perform better than the other. The main difference is that maps in XQuery
> are immutable, which means you pay a little more for some operations (like
> adding a new entry), and you pay a lot less for other operations (llike bulk
> copying).
>
> Michael Kay
> Saxonica
>
>



More information about the talk mailing list