Skip to content

SPARQL pragmas: parse a request once instead of re-reading pragmas in each layer #2014

Description

@bplatz

A SPARQL request that carries a # PRAGMA comment is still parsed more than once. Each layer that applies a pragma reads it from the text with fluree_db_sparql::request_pragmas, and that function runs a full parse. Requests without a pragma comment skip it, because request_pragmas returns early unless some # comment could be a directive.

#2002 removed the extra parse wherever the API already holds the AST: the view and dataset query paths now build their fuel and tracking trackers from ast.pragmas. These extra parses remain, per pragma-bearing request:

Route Extra parses Where
Server query (any SPARQL route) 1 FlureeHeaders::with_sparql_request_pragmas; the route then parses again for its dataset-warning headers
FromQueryBuilder / GraphQueryBuilder with no caller policy +1 GovernanceOptions::from_sparql, before the view loads
Connection-scoped tracked query, no tracking override +1 the floor tracker in query/connection.rs
Multi-query SPARQL alias 3 server min-t collection, server alias authorization (sparql_alias_pragma_opts), dispatcher (sparql_pragma_opts)
SPARQL UPDATE with no tracking headers 2 server header merge, TransactCore::tracker

The cost only matters for large request bodies (multi-MB VALUES payloads) that also carry a pragma.

Possible approach: parse once at the entry point and carry the result down.

  • The server parses once per route and takes the pragmas from that ParseOutput, merging them into the headers and reusing it for the warning headers.
  • The API builders accept already-extracted Pragmas (or the AST) so policy adoption and trackers don't re-read the text.
  • The multi-query server pass hands the alias's pragmas to the dispatcher instead of the dispatcher re-reading them.

This touches signatures in about 15 places in the server and API, which is why #2002 left it out.

Activity

  1. added
    P3Backlog: valid, low payoff-per-effort
    area:sparqlSPARQL/Turtle/TriG/JSON-LD parsing, lowering, UPDATE semantics, W3C conformance
    performancePerformance improvement (release notes: Performance)
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Backlog: valid, low payoff-per-effortarea:sparqlSPARQL/Turtle/TriG/JSON-LD parsing, lowering, UPDATE semantics, W3C conformanceperformancePerformance improvement (release notes: Performance)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions