# Huge Execution Time Difference between stardog studio and snarl api

**URL:** https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767
**Category:** Support
**Created:** [December 15, 2023, 4:08am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767 "2023-12-15T04:08:20Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Cesar](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@Cesar](https://community.stardog.com/u/Cesar)
#### Post date: [December 15, 2023, 4:08am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/1 "2023-12-15T04:08:20Z")

</div>

Hi,

We execute some CONSTRUCT queries, using a block of code similar to the below code. We then convert it to a `List<Statement>` and return it. `sparql` variable below is the text of our construct query.

```auto
    try (Connection connection = getConnection()) {

      GraphQueryResult result = null;
      try {

        GraphQuery query = connection.graph(sparql).dataset(dataset);

        result = query.execute();

        return new ArrayList<>(result.toGraph());
      } catch (StardogException | QueryExecutionFailure e) {
        log.error(e.toString());
        throw new RuntimeException(e);
      } finally {
        if (result != null) {
          try {
            result.close();
          } catch (QueryExecutionFailure e) {
            log.error(e.toString());
          }
        }
      }
    }

```

# Questions

## 1

When we copy the `sparql` text and paste it into the stardog studio and execute it, it is so fast and we easily save the result into a file.  
However, the above code tries to run the same query but takes forever to be finished.

## 2

Besides it loads the data in a lazy way, so we do not know how exactly and when is the right time to run `return new ArrayList<>(result.toGraph());` to return the graph.

Maybe one way is something like below:

```auto
		CloseableIterator<Statement> aResultsIter = new CloseableIterator.AbstractCloseableIterator<Statement>() {
			@Override
			public void close() {
				aResults.close();
			}

			@Override
			protected Statement computeNext() {
				if (aResults.hasNext()) {
					return aResults.next();
				}

				return endOfData();
			}
		};

		return Streams.stream(aResultsIter);
	}

```

is there any other way?

Thank you!

---

<div class="post-metadata">

### Author: ![pavel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/pavel/32/18_2.png) [@pavel](https://community.stardog.com/u/pavel)
#### Post date: [December 15, 2023, 8:34am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/2 "2023-12-15T08:34:44Z")

</div>

As I said in the other ticket, you can always return `result.toGraph()` and be sure that the result is complete and the result set is closed.

I don't know why there's a performance difference. For starters, I'd double check that the query dataset is exactly the same and that you're getting the same results. If both check out, then maybe collect thread dumps to see where things get stuck when you execute your program.

Best,  
Pavel

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [February 7, 2024, 12:34am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/3 "2024-02-07T00:34:04Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [April 4, 2024, 4:44am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/4 "2024-04-04T04:44:09Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [July 8, 2024, 11:40am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/5 "2024-07-08T11:40:58Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [January 11, 2025, 9:28am UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/6 "2025-01-11T09:28:48Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [August 18, 2025, 12:52pm UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/7 "2025-08-18T12:52:13Z")

</div>



---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)
#### Post date: [April 13, 2026, 4:12pm UTC](https://community.stardog.com/t/huge-execution-time-difference-between-stardog-studio-and-snarl-api/4767/8 "2026-04-13T16:12:34Z")

</div>


