0

I am using Apache Jena's QueryFactory class to transform my SPARQL query string into a Query object for manipulation.

The problem I have is that the single snippet of code shown below takes 5 seconds to run, which is unacceptable.

Query query = QueryFactory.create("PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" +
                "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" +
                "\n" +
                "SELECT ?who ?g ?mbox\n" +
                "FROM <http://example.org/dft.ttl>\n" +
                "FROM NAMED <http://example.org/alice>\n" +
                "FROM NAMED <http://example.org/bob>\n" +
                "WHERE\n" +
                "{\n" +
                "   ?g dc:publisher ?who .\n" +
                "   GRAPH ?g { ?x foaf:mbox ?mbox }\n" +
                "}");

I am wondering if anyone could provide a reasonable explanation for this, some way of improving the performance, or another alternative to this code altogether.

Ponsietta
  • 315
  • 6
  • 17
  • 5s should not happen - I mean, yes a parser is used and `ARQ.init()` is likely to be called once at least when the application starts, but other then that your query is small. Can you provide more info about your application, Java setup, Jena version, memory, system ,etc. ? how did you measure the time? – UninformedUser Apr 22 '19 at 13:15
  • @AKSW it's just a simple command-line app and I commented all other code when running it. Granted, I didn't measure the time accurately, only ran it in the IntelliJ IDE and counted how long it took. Jena version is latest stable 3.10.0. Could be IntelliJ is the bottleneck.. will try running from cmd – Ponsietta Apr 22 '19 at 13:49
  • 3
    Just running a command line app is running Java from cold. It's going to do a lot of work one-time such as class loading. Try running the `QueryFactory.create` twice and timing the second call as a quick way to estimate the code of the parse step. – AndyS Apr 22 '19 at 16:44
  • @AndyS you are right, the second call was much faster, I guess it just needs warming up. Thanks! – Ponsietta Apr 25 '19 at 15:59

0 Answers0