Skip to content

feat(P1): 统一运行时依赖图 Graph;dixhttp 快照缓存 - #60

Merged
kooksee merged 6 commits into
v2from
feat/p1-graph-model
Sep 4, 2026
Merged

feat(P1): 统一运行时依赖图 Graph;dixhttp 快照缓存#60
kooksee merged 6 commits into
v2from
feat/p1-graph-model

Conversation

@kooksee

@kooksee kooksee commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

概要

spec 第 3 节实施 P1(实施计划:docs/superpowers/plans/2026-09-04-p1-graph-model.md):

  1. dixinternal/graph.go(新):运行时依赖图 Graph——节点(Type/Provider/Object)+ 边(Declared 声明依赖 / Produced 产物 / Resolved 执行计数)+ 版本号;读写锁保护(dixhttp 并发读安全);线性 searchNodes 检索(P4 倒排的地基)。
  2. Provide 增量建图:产物边 + 声明边(输出类型 → 扁平化输入类型,含 namespace 标记),struct 多输出重复注册幂等(节点/边键用函数值——handleProvide 递归每次新建 providerFn 指针,指针键会去重失效)。
  3. isCycle 迁移:只读投影 declaredAdjacency + 原 detectCycle(确定性语义不变),删除 depGraph/graphDirty/buildDependencyGraph 全量重建。正向改进:struct 输出父类型的字段依赖边现在入图(旧图只看 providers map 键,这类环会漏检)。
  4. 执行计数与对象节点:provider 成功执行 Resolved 边 +1;对象首次入缓存建 Object 节点并递增版本。
  5. dixhttp 快照缓存:反射(ProviderDetails/objects)与全量投影仅在图版本变化后第一次请求发生;未过滤请求返回同一份快照,过滤视图从缓存输入纯函数投影。extractDependencyData 方法删除,改为纯函数 buildDependencyData

附带修复

  • GetFnName 对零值 reflect.Value 调 IsNil 会 panic(provider 节点可不带 fn)——补 IsValid 防护(并发测试抓到)。

验证

  • 行为等价:全部现有测试零改动通过——cycle 锁测试(fix: 聚合查询裸 struct 元素 fail-fast;环路径确定性输出 #57 确定性)、模式锁测试、dixhttp handler 契约、example 19 包
  • 性能:BenchmarkHandleDependenciesWarm 热请求 5.2µs / 13 allocs(仅 JSON 编码,零反射;此前每请求全量 FuncForPC + GetObjects)
  • 全仓 task test(含 example race)+ task lint 0 issues
  • 覆盖率:dixinternal 84.4%(↑)、dixhttp 77.1%(↑)
  • 文档:docs/design.md / design_zh.md 2.2/3 节同步;changelog 已记

…aph rebuild

Declare edges (output type -> flattened input types) are maintained on
Provide inside the new Graph; isCycle projects the adjacency read-only.
Struct-output parent types now also carry their field dependencies —
the old rebuild missed those cycles. detectCycle semantics unchanged
(sorted deterministic traversal, trimmed paths, all lock tests pass
unchanged).

Also fixes GetFnName panicking on zero reflect.Value (provider nodes
may carry no fn).
ProviderDetails/objects reflection and the full projection happen once
per graph version; warm unfiltered requests return the same snapshot
(5.2us, 13 allocs — JSON encode only), filtered views rebuild from
cached inputs without reflection. GetProviderDetails/GetObjects call
sites in stats/packages/type/package handlers now share the cache.
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 882aa87f-019b-4c8d-aa60-f22f50036c00


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kooksee
kooksee merged commit e8afac2 into v2 Sep 4, 2026
3 checks passed
@kooksee
kooksee deleted the feat/p1-graph-model branch September 4, 2026 13:32
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

Successfully merging this pull request may close these issues.

1 participant