You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Late decoding for a default graph of several graphs of one ledger #2015
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.
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:
Harness: a small A/B harness over the bench fixtures, counting instructions retired (the box was busy, so not wall-clock) and allocator calls, four processes per build.
Answers: every scenario's answer was identical on all five builds.
One graph: late members are within noise of main, or better.
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.
Activity
aaj3f commentedon Oct 13, 2026
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:friendedge crossing graphs, readFROMall three (the union default graph agrees within a point).COUNT(*)GROUP BY ?pcountCOUNT(DISTINCT ?s)ORDER BY … LIMIT 10SELECT ?s ?p ?o, 22,500 rowsOPTIONAL 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:
Sidonce 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.