Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: MCP query_graph and shortest_path rebuild a copy of the whole graph on every call

未关闭
#4,191 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@rohit-jsfreaky 已经在做这个了。

开始于 2026年10月7日。

  • #4192 来自 @rohit-jsfreaky —— 未关闭

评估

难度
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 内容生成。

描述

bug
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_text calls _traversal_view(G), which copies every edge of the loaded DiGraph into a new undirected graph on every query (~38k add_edge per query on graphify's own graph).
  • _shortest_path_text builds a sorted nx.DiGraph (or nx.Graph with undirected=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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Graphify-Labs/graphify 的其他 Issue

查看 Graphify-Labs/graphify 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。