Repository navigation
Description
What happened?
With #205, a named variable-length path whose relationships share an equality filter drops failing edges during the walk. On #179's repro that takes the query from 21.4 s to 2.6 s. It is still about 5x slower than the same query written as explicit hops, which finds the same 10 paths:
| Query (debug build, best of 3) | Paths | Time |
|---|---|---|
Three explicit hops, rN.day = 5 on each hop |
10 | 0.49 s |
*1..3 with all(r IN relationships(p) WHERE r.day = 5) |
10 | 2.60 s |
The same with $day instead of 5 |
10 | 2.59 s |
I haven't profiled this with Claude Opus 5.5 yet (on my TDL). Best guess on the cause for now: the named-path operator builds its edge inventory from every edge of the relationship table, 3M here, and evaluates the filter on all of them before the walk starts. The explicit hops read only the edges next to the start node and its neighbours. If that's right, the gap grows with the size of the relationship table, not with the number of matching paths.
Minimal reproducer
The script from #179, run on the branch from #205:
import time
import numpy as np
import pyarrow as pa
from lance_csr import CypherEngine, GraphConfig
rng = np.random.default_rng(0)
n, m = 20_000, 3_000_000
cfg = GraphConfig.builder().node_table("N", "id").rel_table("R", "N", "N", "src", "dst").build()
e = CypherEngine(cfg, {
"N": pa.table({"id": np.arange(n)}),
"R": pa.table({"src": rng.integers(0, n, m), "dst": rng.integers(0, n, m), "day": rng.integers(0, 58, m)}),
}, use_csr=True)
queries = {
"explicit hops": """
MATCH (a:N {id: 0})-[r1:R]->(:N) WHERE r1.day = 5 RETURN count(*) AS n
UNION ALL MATCH (a:N {id: 0})-[r1:R]->(:N)-[r2:R]->(:N) WHERE r1.day = 5 AND r2.day = 5 RETURN count(*) AS n
UNION ALL MATCH (a:N {id: 0})-[r1:R]->(:N)-[r2:R]->(:N)-[r3:R]->(:N) WHERE r1.day = 5 AND r2.day = 5 AND r3.day = 5 RETURN count(*) AS n""",
"all() on *1..3": "MATCH p = (a:N {id: 0})-[:R*1..3]->(:N) WHERE all(r IN relationships(p) WHERE r.day = 5) RETURN count(*) AS n",
}
for name, q in queries.items():
t = time.perf_counter()
rows = e.execute(q).to_pydict()["n"]
print(f"{name}: {sum(rows)} paths in {time.perf_counter() - t:.2f}s")Environment
- lance-csr version (or commit): 0.14.0, branch
perf/prune-paths-by-all-predicate(perf(cypher): prune named paths by all() equalities and accept bare booleans #205), debug build - Python version: 3.12
- Operating system and architecture: macOS 26, arm64
- For performance issues: 20,000 nodes, 3M random edges, Apple silicon laptop, timings above (release builds not measured)
Activity
perf(cypher): walk the csr for named trail paths (hyperdimensionalcom…