Repository navigation
perf(response-stream): prune unreachable paths and cache blocking edges - #271
Conversation
|
All contributors on this pull request have signed the CLA. |
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
|
Hi @laipz8200, Could you please review this when you have time? |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Thanks for working on this! In an offline A/B test on the Graphon 0.8.0 revision pinned by Dify 1.19.0, adapting this change brought median This would substantially reduce startup latency for our project. We’d appreciate it if a maintainer could approve the pending CI run and review this PR when possible. |
|
thanks @quhaobo11 , I hope that they merge this soon |
Bring the repository knowledge review from langgenius#394 into PR langgenius#271 to resolve the documentation freshness failures. Preserve the response-stream path pruning and per-response blocking-edge cache while integrating the current main branch.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
laipz8200
left a comment
There was a problem hiding this comment.
LGTM, thank you for your contribution!
|
AI-assisted analysis and drafting with Codex using gpt-6.1-sol. I tested the final PR head, Results
The timing is a single local diagnostic sample, not a capacity benchmark. No workflow YAML or customer content is included here. Smaller instances of the same all-paths-reach-End topology produced these counts:
ComplexityBuilding the reverse adjacency index costs O(V + E), and the per-response cache reduces blocking classification to at most one call per distinct path edge. However, If P is the number of paths to a response and L is their average length, materializing the complete paths alone requires at least Omega(P * L) time and storage; copying path and visited state adds further traversal cost. For the n-stage topology above, P = 2^n and L grows linearly with n, so initialization time and retained path storage remain Theta(n * 2^n).
Reverse-reachability pruning is useful when large subgraphs cannot reach the response. It cannot prune this topology because every branch can reach the same End. A follow-up using a compact response-eligibility representation, such as incremental reachability, is still needed to eliminate this remaining exponential case. |
Important
!Related Issue
Refs langgenius/dify#41851. Also related to langgenius/dify#38852.
Summary
Response-stream initialization prepares paths before the first graph-start event.
For each response node, the current DFS explores branches that cannot reach it;
branch/merge-heavy graphs can therefore incur exponential useless traversal.
Blocking-edge classification is also repeated for edges shared by many paths.
This change:
The regression tests use synthetic graphs only: no private workflows, prompts,
credentials, customer data or infrastructure identifiers are included.
Evidence and Limits
The equivalent backport was measured on Dify 1.15.0 / Graphon 0.5.3 before adapting
it to this repository's current main. A 157-node, 203-edge graph with nine response
nodes produced exactly the same 49,182 ordered blocking paths before and after.
A matched initialization comparison improved from 6.709 s to 0.409 s. Five direct
staging API requests subsequently started in 0.705-1.669 s, completed without node
exceptions, and preserved multi-turn recall and a tool-driven authentication-entry
branch. These are diagnostic samples, not a capacity/p95 benchmark or timings for
the current-main test runner.
Complete-path enumeration can still be exponential when all those paths genuinely
reach the target. This PR deliberately retains that representation; it does not
claim to fix every workflow latency source.
Synthetic operation counts are separate from those wall-clock samples: a
22-node/27-edge dead-branch graph makes 255 adjacency calls before and 24 after
(22 reverse-index scans plus two forward expansions), returning one identical
complete path. A shared-edge diamond classifies five distinct edges instead of
six path-edge occurrences. Peak live path-object count and peak memory have not
been measured; no peak-memory reduction is claimed.
Correctness Contracts
Both traversals use the same configured
get_outgoing_edges()topology. Runtimeedge state and conditional handles do not filter that method; variable selectors
affect blocking classification, not path eligibility. Pruning does not introduce
early condition evaluation. A reverse-reachability superset remains conservative;
excluding any edge available to forward traversal would violate the contract.
The blocking cache is local to one
_build_paths_map()call, with a fixed graphand response selector set. It is not shared across response nodes, retained across
initializations, or serialized into snapshots.
No Dify dependency bump is included. After a Graphon release, Dify can consume the
fix through its normal dependency update; this PR should not prematurely close
the Dify tracking issue.
Validation
Validated on Python 3.12.11 against main at
788086fe16ab46b2ba290bb48873b6145862377c:pytest -n 2 --tb=short: 798 passed.uv lock --check,ruff format --check,ruff check --no-fix, andty check: passed (the recipe-equivalent checks;justis not installed locally).The upstream Python 3.12/3.13 CI matrix remains the final platform check.
Checklist
!