主题
pipeline · 缓存组合
createPipeline 把 bind、layout、build 串成一帧,并按阶段复用未变化的产物。
签名
ts
function createPipeline(options?: PipelineOptions): Pipeline;
interface Pipeline {
run(input: PipelineInput): Result<PipelineFrame>;
runAsync(input: PipelineInput): Promise<Result<PipelineFrame>>;
}PipelineFrame 包含:
boundthemelayoutscenediagnostics- 每一段的
stats: { ms, cached }
runAsync 会使用 bindDocumentAsync,因此可以等待异步 Standard Schema。 run 保持同步;遇到异步 schema 时会在 bind 阶段发出回落诊断。
缓存边界
| 变化 | 从哪一段重跑 |
|---|---|
| 文档变了 | bind → layout → build |
| tokens 变了 | build |
| overlay 变了 | build |
| router 变了 | route → build |
| measurer fingerprint 变了 | measure → place → attach → route → build |
| 全部相同 | 整帧命中缓存 |
缓存不会改变数据流:每一帧仍然返回完整 PipelineFrame,只是 stats.cached 标明哪些阶段复用了结果。
与 handle 的关系
createDrawHandle = Pipeline + Host。只需要几何、场景或 SVG 时直接用 Pipeline; 需要把 patch 落到 DOM 时才用 handle。