Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

深度较大的数据初始渲染时,dfs递归导致内存溢出 #75

Open
Kijin-Seija opened this issue Mar 9, 2022 · 1 comment
Open

Comments

@Kijin-Seija
Copy link

使用g6时遇到了一个问题,如下demo

demo

image

demo中是2000条首尾相连的数据,布局模式使用Dagre

定位到 https://github.com/antvis/layout/blob/master/src/layout/dagre/src/order/init-order.ts 里面的方法dfs

const dfs = (v: string) => {
    if (visited.hasOwnProperty(v)) return;
    visited[v] = true;
    const node = g.node(v);
    if (!isNaN(node.rank as number)) {
      layers[node.rank as number].push(v);
    }
    g.successors(v)?.forEach((child) => dfs(child as any));
  };

此demo中图的深度较大,猜测是递归pending的dfs函数过多导致内存溢出。本地调试改为bfs后不再报错(但导致了初始化时图不居中)

const dfs = (v: string) => {
    let cur = [v];
    while(cur.length) {
      let temp: any[] = [];
      cur.forEach((item: any) => {
        if (visited.hasOwnProperty(item)) return;
        visited[item] = true;
        const node = g.node(item);
        if (!isNaN(node.rank as number)) {
          layers[node.rank as number].push(item);
        }
        temp = [...temp, ...(g.successors(v) || [])];
      });
      cur = temp;
    }
  };

image

不知是否有相关的配置可以解决这个问题,或者说一个不成熟的建议是提供给用户可选dfs或者bfs进行初始布局?

@Kijin-Seija
Copy link
Author

有大佬能帮忙解答一下吗,对应的代码,相关的demo都齐全,我这边因为对整体工程还不太了解,不敢贸然提pr。感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant