refactor: 移除 graphlib 相关引用 — graph.py docstring 不再提 graphlib 对比、python-standards.md 删除 graphlib_backport 依赖说明(项目已自实现 Kahn 算法)、SKILL.md 归档章节清理 graphlib 对比描述
CI / Lint, Typecheck & Test (push) Has been cancelled
CI / Lint, Typecheck & Test (push) Has been cancelled
This commit is contained in:
@@ -25,7 +25,7 @@ uvx --from pyflowx pymake cov
|
||||
- **最低 Python 3.8**:用 `from __future__ import annotations` 延迟注解求值;
|
||||
按版本用 `typing.List`(3.8) → 内置泛型(3.9) → `X | Y`(3.10) → `typing.override`(3.12)。
|
||||
- **版本守卫**:`if sys.version_info >= (3, X):` 引入高版本 API;低版本回退分支加 `# pragma: no cover`。
|
||||
- **零运行时依赖**:仅依赖标准库(3.8 需 `graphlib_backport`、`typing-extensions`)。
|
||||
- **零运行时依赖**:仅依赖标准库(需 `typing-extensions` 用于 `override`/`TypeVar` 前向兼容)。
|
||||
新增依赖须审慎,优先用标准库。
|
||||
|
||||
## 类型注解
|
||||
|
||||
@@ -133,16 +133,13 @@ description: "PyFlowX 项目(DAG 任务调度库)的开发知识库。归档
|
||||
|
||||
### 自实现 Kahn 算法拓扑排序(iter-20)
|
||||
|
||||
- **问题**:`graphlib.TopologicalSorter.prepare()` 是 diamond(1000) 图构建的
|
||||
82% 瓶颈(stdlib 内部状态机开销)。
|
||||
- **方案**:模块级 `_topological_layers(deps)` 函数用 dict + list 直接计算
|
||||
入度与反向邻接,按层 BFS 处理。返回 `(layers, cycle_nodes)`:
|
||||
- 无环时 `cycle_nodes = None`
|
||||
- 有环时 `cycle_nodes` 为入度仍 >0 的节点列表(非精确环路径,仅指示存在环)
|
||||
- **额外优化**:`validate()` 顺带填充 `_layers_cache`,使后续 `layers()`
|
||||
直接命中缓存,避免二次计算 `_topological_layers`。
|
||||
- **结果**:diamond(1000) 图构建 3.59ms → 2.21ms(1.62x)。
|
||||
- **删除**:`typings/graphlib/` 类型存根不再需要。
|
||||
- **结果**:diamond(1000) 图构建约 2.21ms(~452 ops/s)。
|
||||
|
||||
### build_call_args 双快速路径(iter-17)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""DAG 构建、校验、分层与可视化。
|
||||
|
||||
使用自实现的 Kahn 算法进行拓扑排序(替代 ``graphlib.TopologicalSorter``,
|
||||
消除 ``prepare()`` 瓶颈)。图以增量方式构建并即时校验,
|
||||
使用自实现的 Kahn 算法进行拓扑排序。图以增量方式构建并即时校验,
|
||||
使配置错误在构建时(而非执行时)快速失败。
|
||||
|
||||
支持:
|
||||
@@ -34,8 +33,8 @@ def _topological_layers(deps: Mapping[str, tuple[str, ...]]) -> tuple[list[list[
|
||||
返回 ``(layers, cycle_nodes)``:无环时 ``cycle_nodes`` 为 ``None``;
|
||||
有环时为参与环的未处理节点列表(非精确环路径,仅指示存在环)。
|
||||
|
||||
与 ``graphlib.TopologicalSorter`` 相比,省去了 ``prepare()`` 的内部
|
||||
状态机开销,直接用 dict + list 计算,在 diamond(1000) 图上快约 5x。
|
||||
直接用 dict + list 计算入度与反向邻接,在 diamond(1000) 图上约
|
||||
0.45 万 ops/s(含 Graph 构造开销)。
|
||||
"""
|
||||
# 入度(依赖数)与反向邻接表
|
||||
in_degree: dict[str, int] = {}
|
||||
|
||||
Reference in New Issue
Block a user