Claus Stadler created JENA-1862:
-----------------------------------

             Summary: Query.cloneQuery is slow
                 Key: JENA-1862
                 URL: https://issues.apache.org/jira/browse/JENA-1862
             Project: Apache Jena
          Issue Type: Improvement
          Components: ARQ
    Affects Versions: Jena 3.14.0
            Reporter: Claus Stadler


This is a follow up to JENA-1861 which is about the thread safety of Query 
objects. As sharing a Query object across threads may introduce race condition, 
the obvious workaround would be to just clone it. However, the current 
implementation serializes the query to string and then re-parses it which 
causes a very high overhead (for my use case it became the top entry in the 
VisualVM profiler).

Proposal:
* Extend ElementTransformCopyBase with a 'alwaysCopy' flag analogous to 
ExprTransformCopy
* Add a new constructor to ExprTransformApplyElementTransform(ElementTransform 
transform, boolean alwaysCopy) so that the alwayCopy flag of the underlying 
ExprTransformCopy can be set to true
* Implement clone using syntatic transforms as below

{code}
public static Query fastClone(Query query) {
    ElementTransform eltXform = new ElementTransformCopyBase2(true);
    ExprTransform exprXform = new ExprTransformApplyElementTransform2(eltXform, 
true);
    Query result = QueryTransformOps.transform(query, eltXform, exprXform);
    return result;
}
{code}

This approach 'work-for-me' and I can create a pull request for this, but maybe 
there are more subtleties to the outlined approach that need to be considered?




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to