Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-1862

Query.cloneQuery is slow

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Jena 3.14.0
    • Jena 3.15.0
    • ARQ
    • None

    Description

      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 conditions, 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
      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;
      }
      

      This approach 'works-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?

      Attachments

        Issue Links

          Activity

            People

              andy Andy Seaborne
              Aklakan Claus Stadler
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 50m
                  2h 50m