Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Cerrado
#4,191 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #4192 de @rohit-jsfreaky — cerrado sin fusionar

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
performance

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
124k
Forks
11.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Graphify-Labs/graphify

Todos los issues de Graphify-Labs/graphify

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.