Skip to content

Late decoding for a default graph of several graphs of one ledger #2015

Closed

Description

@bplatz

Since #2004, a default graph made of ≥2 graphs of one ledger (the union default graph, or FROM naming several of a ledger's graphs) scans each member with eager materialization (DatasetOperator::member_ctx_for). A GRAPH scope also decodes every encoded binding it hands to such a scope (ScopeExit in graph.rs). This fixed a cross product: the multi-graph scope has no graph view, so join substitution left EncodedSid bindings unbound.

Cost: every row decodes subject IRIs and literals as it is scanned. That includes count- and group-only queries, which used to keep IDs encoded through to output.

Possible fix: only NUM_BIG handles are per-graph. Give the multi-graph scope a decode-only view (any member's) for the decoding sites to use, while has_binary_store() stays false so the single-graph fast paths remain off. Members would then eagerly decode NUM_BIG only. Roughly 38 graph_view() call sites in fluree-db-query would need to decide whether to use it.

Measure first: compare eager and late decoding on an indexed ledger over FROM <L> FROM <L#g> (or with the union on), for a count/group query and a join query. Only build this if the gap is material.

Acceptance:

  • joins_over_several_graphs_of_an_indexed_ledger stays green.
  • A new test shows NUM_BIG values from different members decoding against their own graph's arena.

Activity

  1. added
    P3
    area:query
    on Oct 3, 2026
  2. aaj3f commented on Oct 13, 2026

    @aaj3f
    Contributor

    You set the bar here as "measure first, only build this if the gap is material", so I measured it. I think it's material, but I'd like your read before we build it.

    The comparison is #2010 as it lands, where members decode eagerly per #2004, against the same code with late members. The figures are instructions per query, and the two versions give the same answers. The fixture is 3,000 people across three named graphs of one indexed ledger, every ex:friend edge crossing graphs, read FROM all three (the union default graph agrees within a point).

    Query Eager Late Change
    COUNT(*) 371.5M 63.5M 5.9× fewer, allocations −84%
    GROUP BY ?p count 386.3M 73.2M 5.3× fewer
    COUNT(DISTINCT ?s) 85.7M 8.65M 9.9× fewer (8.1× vs main today)
    ORDER BY … LIMIT 10 77.2M 18.6M 4.1× fewer
    Join, 12,000 rows 1,107M 923M −16.6%
    SELECT ?s ?p ?o, 22,500 rows 1,128M 906M −19.7%

    OPTIONAL and FILTER come out 5–8% lower. Peak memory is about equal: within a few MiB on the aggregates and on #1973's query over two graphs.

    A bit on method:

    What I'd propose is a single follow-up PR once #2010 lands, built and tested on main:

    • A decode view. A scope over several graphs of one ledger decodes through a view of the ledger's shared dictionaries, which refuses arena values. Single-graph fast paths stay off.
    • Arena-only member decode. Members stay late and decode only big numbers and vectors, whose handles are per graph.
    • One substitution across members. A correlated scan resolves an encoded subject to its Sid once for all members, which share the namespace table.

    Does that clear your bar? If you'd still rather keep eager, or want another shape measured first, I'm happy to talk it through.

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

    P3area:query

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions