[Bug]: MCP query_graph and shortest_path rebuild a copy of the whole graph on every call
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- performance
调研方向
Read graphify/serve.py: _traversal_view(G) and _shortest_path_text, plus the trigram index caching pattern in _get_trigram_index(G) which stores state on G.graph and is invalidated by a hot reload. Done means each rebuilt structure is built once per loaded graph with byte-identical query answers, verified by the reproduction script in the issue. However, the reporter states a fix is ready and PR #4192 is already open against this issue, so it is not available as a first contribution.
由索引模型根据 Issue 内容生成。
描述
Pre-flight checks
- I have checked the Troubleshooting section in the README
What happened?
On a warm MCP server, most of a query_graph call and nearly all of a shortest_path call is spent rebuilding a structure that is the same for every call on the same graph:
_query_graph_textcalls_traversal_view(G), which copies every edge of the loaded DiGraph into a new undirected graph on every query (~38kadd_edgeper query on graphify's own graph)._shortest_path_textbuilds a sortednx.DiGraph(ornx.Graphwithundirected=true) from every edge on every call (sorted for the deterministic route, #2074). The path search itself takes under 1 ms.
The _traversal_view docstring chose this on purpose ("A fresh copy per query rather than a cached one ... only the edge dicts are duplicated"), i.e. for memory/simplicity, not correctness. The trigram index already uses the safe alternative: build once and cache on G.graph, which a hot reload invalidates by swapping in a new graph object.
Expected: build each structure once per loaded graph; answers unchanged.
Steps to reproduce
# graphify's own repo, built graph (18,865 nodes / 38,458 edges)
python - <<'EOF'
import time, statistics, graphify.serve as S
G = S._load_graph("graphify-out/graph.json"); S._get_trigram_index(G) # what the server does at load
t=[]
for _ in range(10):
s=time.perf_counter(); S._shortest_path_text(G, {"source": "load_cached", "target": "save_cached"}); t.append(time.perf_counter()-s)
print("shortest_path median ms", statistics.median(t)*1000)
EOF
# profile: almost all time is building the sorted DiGraph; nx.shortest_path on it is < 1 ms.
# same for query_graph: ~half the call is _traversal_view copying every edge.
Error output or graph output
shortest_path: ~93 ms of a ~108 ms call is building the sorted DiGraph; nx.shortest_path on it: 0.24 ms
query_graph: _traversal_view = ~half of a warm call (406,495 add_edge calls over 10 queries)
Warm-server medians on graphify's own graph (v8 f765dcb): query_graph 270-430 ms, shortest_path 100-235 ms (laptop, varies with thermal state).
Graphify version
0.9.79 (f765dcb)
Operating System
Windows
Python Version
3.12
Installation Method
built from source (git clone)
Additional Environment Details
No provider keys set. Measured in-process on the MCP code path (_load_graph + _query_graph_text / _shortest_path_text).
Additional context
A fix with before/after numbers and identical-output checks is ready; PR right after this.
- 主要语言
- Python
- 星标
- 124k
- 派生
- 11.9k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Graphify-Labs/graphify 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
Graphify-Labs/graphify#3763 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
Graphify-Labs/graphify#3611 · 1 条评论 ·
维护者通常 1 天内回复
-
Nix support未关闭
难度 2/5 1-3 小时 新手友好度 62/100
Graphify-Labs/graphify#3193 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
Graphify-Labs/graphify#2871 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
Graphify-Labs/graphify#2865 ·
维护者通常 1 天内回复
查看 Graphify-Labs/graphify 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
mishraprafful/multihull#150 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
python-caldav/caldav#735 ·
维护者通常 1 天内回复
-
bug triage
难度 2/5 1-3 小时 新手友好度 68/100
mealie-recipes/mealie#8682 ·
维护者通常 1 天内回复
-
good first issue lane:repo
难度 2/5 1-3 小时 新手友好度 85/100