chore(task): archive 09-08-junction-reference-fidelity

This commit is contained in:
que01 committed 2026-09-17 09:14:38 +08:00
1 parent 55888e8d91
commit 79590d3d0f
45 files changed
+2 -2

No files matched your search

@@ -0,0 +1,23 @@
# Center pavement and vehicle trajectory audit — 2026-09-14
Scope: investigation and implementation plan only; no implementation changes.
Reproduced with workbench-data/import-fE8XI7/source.osm and its active area-config.snapshot.json: four nodes (8005332807, 8024512135, 8024512145, 8024512147), core radius 21 m. Do not substitute the older five-node/24 m script.
## Confirmed findings
- Actual compilation publishes no complex-core. Diagnostic: complex-junction-core-closure-unsupported / core-closure-invalid. Eight complex-approach surfaces and four complex-corner-fillet surfaces remain.
- complex-junction.js constructs each corner fill as [...curve, center, curve[0]]. With the core absent, these center-directed fans explain the triangular gaps. This is not evidence of a triangulation-rendering defect.
- buildCoreClosure in junction-boundary-graph.js selects one section per arm when arms contain multiple carriageways, discarding other entry seams from the candidate core. It then sorts endpoints by angle and rejects zero edges, unpaired edges, insufficient area or self-intersection with the same generic reason. Which individual predicate fails must be instrumented before changing construction.
- compileConnectors in native-road.js works on enabled model.connections by node. Four-segment nodes use a quadratic curve through an endpoint node as control; other through movements use a straight chord; other turns use cubic curves with lane endpoint tangents. Fixed sampling is 12 segments. Existing tangent-based construction therefore does exist, but is not used consistently.
- validateConnectorContainment checks samples against one junction exterior ring and skips kind=cluster; it does not establish swept vehicle clearance from island holes or authoritative complex pavement. No claim yet that a particular observed connector joins the wrong lane; that requires source/destination tracing and measured evidence.
## Implementation sequence
1. Establish reproducible metrics for this saved configuration: all entry section IDs, core failure predicate, pavement connected components and unexplained gap regions; each movement's source/destination lane and endpoint/tangent errors. Export pavement and trajectory overlays separately and together. Preserve current four islands as a regression invariant.
2. Repair core closure using every valid carriageway entry seam and explicit connecting boundary edges. Reuse BoundaryGraph and polygon-clipping; validate a simple closed boundary, union with approach/turn pavement, and subtract justified non-drivable islands/exclusions. Crosswalks are markings on pavement, not holes. Do not force-fill a convex hull or disable closure validation.
3. Trace cluster movements across internal source connections to external lane ports, preserving turn restrictions and source provenance. Determine whether current node-level connectors duplicate or omit these movements before replacing them. Lane endpoints/tangents and pavement must consume the same entry sections.
4. Use lane endpoint positions and tangent directions for all connector shapes, including offset through movements. Begin with existing cubic machinery; constrain/control curvature and adapt sampling by geometric error. A cubic with tangent continuity does not automatically give curvature continuity across road joins. Add curvature limits or curvature-transition construction where required. Validate the full path and, with an explicit vehicle envelope, swept clearance against final drivable region and islands. Crossings between different traffic streams are not automatically errors.
5. Acceptance: all expected external entries connect to continuous pavement; no unexplained holes; four islands/green polygons retained; movement IDs and permitted lane pairings correct; endpoint error <= 1 cm, measured endpoint tangent error <= 1 degree; no self-return/cusp or island penetration. Establish vehicle-specific minimum radius before declaring trajectories physically drivable. Include T/Y/oblique/multi-carriageway and short-source counterexamples.
Deliver as one reviewed change across pavement and trajectories after real-workbench visual verification. Do not archive parent task from local facility tests. Remaining uncertainty: exact closure rejection predicate, abnormal connector IDs, whether those displayed lines include lane separators as well as connectors, and necessary vehicle curvature assumptions.
@@ -0,0 +1,20 @@
# 当前证据与通用问题
## 图像观察
三组图显示角部设施离散、形态趋同和内部空间组织不足。紫色连接线/节点等属于调试显示,不能据此断定铺装或实际标线错误。路口 2 的 T 形判断、图像与 OSM 对应关系均待核实;禁止将截图观察硬编码成拓扑真值。
## 代码入口(规划时)
- src/compile/complex-junction.js:17 resolveComplexJunctionTopology:以来源和方向归组;独立通道/分隔关系需要显式保留。
- src/compile/complex-junction.js:150 boundaryParts;约 325 行按夹角与过街框架生成岛体/小斑马线;约 550 行由进口端点排序生成核心;约 603 行生成独立进口矩形。彼此缺少统一边界所有权。
- src/compile/complex-junction.js:698 classifyJunctionShape:有形态分类,但主要生成规则仍共用包络。
- src/compile/junction-topology.js:29 structureFromTopology 和 junction-structure.js:已有来源、臂、角部、设施稳定键,但结构主要是输出读模型;不宜直接把展示 schema 当可求解计划。
- src/compile/direct-edit-solver.js:276 clusterArms 再次归组,可能与几何生成器方向采样/来源判断漂移;规划需统一纯拓扑解析。
- src/compile/native-road.js:3198 trimLineAtComplexCluster 及所有调用:最近修复只为道路面传 per-road 半径,其他裁切消费者仍可能使用默认半径,需跨图层审计。
- src/compile/direct-edit-solver.js:17 引入 complexJunctionMetrics,而其所在模块读取参考文件。后端规范要求 resolver 无 IO,应将预加载参数与纯计算分离。
- workbench/client/src/components/ParameterPanel.tsx 和 App.tsx:复用现有编辑通道;要验证预览先于 Enter 返回、批量修改已有约束、取消与旧响应等场景,避免只证明请求发生。
## 设计约束
遵守 .trellis/spec/backend/direct-edit-api.md、frontend/direct-edit-client.md;既有实现与规范不一致处需显式记录修正。数据中没有路缘/岛体精确形状时,只能推断或人工校正,不能宣称全自动真实还原。
@@ -0,0 +1,38 @@
# Geometry Library Evaluation
日期:2026-09-11
## 结论
首选 `polygon-clipping`(MIT)作为局部米制平面区域布尔运算库,配合项目已有的 `rbush` 空间索引。保留现有 `JunctionBuildPlan` 和 `BoundaryGraph` 作为来源拓扑与共享边界权威,不引入通用图框架替代道路来源身份。
## 候选比较
| 库 | 适合能力 | 主要问题 | 决策 |
| --- | --- | --- | --- |
| `polygon-clipping` | union/intersection/difference/xor;Polygon/MultiPolygon;适合中心区域、排除区、安全岛可行域 | 不负责道路语义、单位和拓扑来源 | 首选补充 |
| `@turf/*` | buffer、lineOffset、空间关系和地理验证;可按模块引入 | 完整包较重;经纬度计算不应成为内部几何权威 | 作为可选验证/偏移工具 |
| `JSTS` | 较完整的 GEOS/JTS 类几何算法 | 包体、API 和维护复杂度偏高 | 后备方案 |
| `clipper2-js` | 高精度平面裁切和偏移 | 当前运行时与维护兼容性需额外验证 | 暂不采用 |
| `graphlib/graphology` | 通用图遍历 | 不解决几何边界,不能替代 OSM 来源拓扑 | 不采用 |
## 目标数据流
```text
JunctionBuildPlan
-> BoundaryGraph(来源边、共享边、排除区)
-> polygon-clipping(区域 union/intersection/difference)
-> CornerFeasibleRegion
-> IslandRegion
-> CrossingRegion
-> 统一连通/自交/重叠/接缝验证
```
局部米制投影、稳定来源键、编辑约束和 GeoJSON 输出仍由项目代码负责。第三方库只接受已经投影到局部平面坐标的环,并返回经过规范化的区域结果;不得让布尔运算输出顺序决定来源身份。
## 引入前验证
- 在独立纯函数测试中验证凹形、孔洞、相切、重叠和多区域结果。
- 验证许可证、Node CommonJS、Vite 浏览器构建和包体影响。
- 先替换 `ringsOverlap` 等局部几何判断,再接入中心区域求解;不先改编辑协议或 UI。
- 如果库无法稳定保留共享边引用,则只用于可行域裁切,BoundaryGraph 仍保留边界所有权和接缝计算。
@@ -0,0 +1,47 @@
'use strict';
// Run from the repo root with node --require <this file> test/<suite>.js.
// This one-off comparison retains the pre-refactor generator as its oracle.
const assert = require('node:assert/strict');
const path = require('node:path');
const Module = require('node:module');
const { execFileSync } = require('node:child_process');
const root = path.resolve(__dirname, '../../../..');
const filename = path.join(root, 'src/compile/complex-junction.js');
const baseline = new Module(filename, module);
baseline.filename = filename;
baseline.paths = Module._nodeModulePaths(path.dirname(filename));
baseline._compile(
execFileSync('git', ['show', '1679d1b:src/compile/complex-junction.js'], { cwd: root, encoding: 'utf8' }),
filename,
);
const current = require(filename);
const build = current.buildComplexJunctionGeometry;
let comparisons = 0;
const shapes = new Set();
const diagnostics = new Set();
let shifted = 0;
let crossingEdits = 0;
current.buildComplexJunctionGeometry = function (model, cluster, helpers) {
const values = {};
const functions = {};
for (const [key, value] of Object.entries(helpers)) {
(typeof value === 'function' ? functions : values)[key] = value;
}
const copied = structuredClone({ model, cluster, values });
const expected = baseline.exports.buildComplexJunctionGeometry(copied.model, copied.cluster, {
...copied.values,
...functions,
});
const actual = build(model, cluster, helpers);
assert.deepStrictEqual(actual, expected, `generator output changed for ${cluster.id}`);
comparisons++;
shapes.add(actual.shape?.kind || 'early-return');
for (const item of actual.diagnostics) diagnostics.add(item.rule);
if (helpers.clusterIslandOffsetMeters) shifted++;
if (helpers.clusterCrossingControls?.size) crossingEdits++;
return actual;
};
process.on('exit', () => {
console.log('Generator parity:', { comparisons, shapes: [...shapes], shifted, crossingEdits, diagnostics: [...diagnostics] });
});
@@ -0,0 +1,47 @@
# 复杂路口生成器结构整理
用户于 2026-09-16 确认实施代码审阅提出的结构重构。
## 边界与设计
现有 buildComplexJunctionGeometry 超过千行,阶段之间依赖 arm 上的可变字段和共享集合。本轮将入口整理为可读的阶段编排,抽取进口、过街布局、角部组合、位移联动和结果装配;角部组合继续拆出有明确职责的局部函数。阶段输入输出显式传递,避免通用可变 context。
实现范围为 src/compile/complex-junction.js 及必要的同目录内部模块。保留公开导出、运算顺序、坐标、Feature 顺序、ID、诊断和失败路径。清理本轮相关的无用变量、导入和过时注释;诊断内容不在此次改变。复用既有几何求解模块,不引入框架或新的配置机制,不改 UI 或几何算法。
## 验证计划
1. 保存重构前生成器,对实际测试输入逐次深比较完整返回值。
2. 运行现有几何、编辑及完整 npm test 回归;既有失败需与基线区分,禁止刷新快照隐藏差异。
3. 运行格式、客户端类型及 git diff --check;审阅阶段依赖和失败路径。
4. 记录重构结果与验证证据,不关闭父任务的其他未完成验收。
## 实现与差分结果
生产修改仅位于 `src/compile/complex-junction.js`。主函数从 1021 行缩为约 159 行;同文件私有函数分别承担阶段编排及单个设施构建,最大新函数约 115 行。没有新增公开导出或依赖。删除两个无用导入和两项无用坐标计算;保留历史诊断并注明其兼容性原因。
差分工具最初位于 `/private/tmp/complex-junction-refactor-parity.cjs`,现保留在同目录 `geometry-refactor-parity.cjs`。用 Node Module 加载基线提交 `1679d1b` 的生成器,将每次实际调用的输入复制后交给旧函数,再对完整返回值执行 `assert.deepStrictEqual`。45 次比较全部一致:主测试流 41 次,单独 island-offset 测试 4 次(其中 3 次非零外移)。覆盖正交、偏置十字、T 形、多臂和节点不足返回,以及无效断面、短过渡、排除区、岛体求解失败、核心闭合失败、过街编辑等诊断路径。
检查结果:
- `npm test` 的代码、几何、编辑、API、工作台导入检查通过,最后 `test/fixtures.js` 失败。该快照差异在重构前已单独复现,重构后输出哈希相同;未刷新基线。
- `node --require /private/tmp/complex-junction-refactor-parity.cjs test/junction-island-offset.js` 通过。
- 客户端类型检查、191 项客户端单测通过。
- 本次源文件格式和 `git diff --check` 通过。全仓 `format:check` 在未修改的 `junction-facility-composition.js` 失败;对 HEAD 原文运行 Prettier 同样失败。
- `npm run test:e2e` 通过:生产构建及 12 项浏览器回归,包含三臂复杂路口控制编辑、保存和刷新。保留既有 bundle 大小提示。
- 独立代码复核通过,无新增修复:核对角部失败依赖、Feature/诊断顺序、共享过街位移和停止线联动。
本轮未提交,父任务保持进行中。历史“角部设施已省略”诊断与实际默认生成行为的矛盾保留为单独行为修正事项。
## 后续模块边界评估(2026-09-16)
阶段编排已经从入口函数中抽出,但 `complex-junction.js` 仍保留了局部米制计算、道路臂包络、圆角相交、人行道接缝和环验证等无状态几何代码,导致文件仍有 1685 行。它们不依赖构建阶段、Feature 发布或诊断顺序,已迁入 `complex-junction-geometry.js`,入口文件降为 1472 行。
下一条清晰边界是 `complex-junction-facilities.js`:进口/停止线、道路臂过街、角部组合和位移联动共用可变的 arm frame,必须作为一个整体迁移;把它们逐个拆成更多小模块会掩盖阶段依赖。核心/入口面/统一铺装可作为之后的 `complex-junction-surfaces.js`。建议在当前功能任务结束并提交现有工作后,以完整输出差分为保护再实施这两次迁移,避免在仍频繁调整的设施算法中扩大冲突面。
本次几何模块提取保持输出:两组设施测试与 island-offset 测试通过,差分脚本对 5 次复杂路口完整返回值比较一致;铺装、落面和拓扑反例测试通过,变更文件 Prettier 与 `git diff --check` 通过。
随后迁出 `complex-junction-surfaces.js`:核心面、进口面与统一铺装区域现在作为一组独立的 surface 阶段。入口文件从 1473 行降至 1301 行。铺装、落面、拓扑反例与 island-offset 回归通过;差分脚本对 9 次复杂路口完整返回值比较一致,包含无效入口、T 形、圆角降级及非零岛体外移。
最后迁出 `complex-junction-facilities.js`:进口与停止线、道路臂过街、角部组合及共享位移共同拥有 arm frame 的写入、消费和最终应用,因此保持为单个模块。入口文件从 1301 行降至 367 行,只保留拓扑/指标/边界图、阶段编排和发布。迁移中补回形态分类所需的 `normalizeHeading` 与 `positiveHeadingDelta` 纯几何导入。设施组合、岛体外移、铺装、落面和拓扑反例通过;差分脚本对 5 次完整返回值比较一致,包含非零岛体外移。
完整 `npm test` 通过全部代码、几何、编辑 API 和工作台导入检查,最后仍在已有 `test/fixtures.js` 快照差异退出;该差异与重构前记录一致,未更新基线。首次完整回归暴露 facilities 模块遗漏 `ringsOverlap` 依赖,已补入并重跑。客户端类型检查和变更文件格式检查通过。
@@ -0,0 +1,142 @@
# Phase 0 Audit: Current Complex-Junction Construction
Date: 2026-09-08
## Scope and evidence
This audit uses source-independent synthetic fixtures in
`test/junction-build-plan-counterexamples.js`. They deliberately do not contain
the reference image names, OSM object IDs, place names, or fixed real-world
coordinates. The file records the old behaviour as a baseline; phase 1 must
replace its absence assertions with positive `JunctionBuildPlan` assertions.
## Findings
### 1. Source identity survives, but grouping and geometry have separate rules
- `src/compile/native-road.js:2823-2841` groups ordinary junction approaches by
`segmentId`, sums both directions into one width, and selects the first road
for the approach line.
- `src/compile/complex-junction.js:17-89` creates one complex carriageway per
existing approach, then groups them into an arm when heading differs by less
than 20 degrees (`:60-71`). The direct-edit solver repeats that independently
in `src/compile/direct-edit-solver.js:210-297`, including its own line and
tangent sampling (`:254-258`, `:277-296`).
- Stable keys use source identity (`complex-junction.js:47-88` and
`junction-topology.js:3-9`), which is reusable. But an arm becomes the
operative geometry unit: the core uses one envelope per arm
(`complex-junction.js:551-566`), and arm crossings start from the
representative (`:244-247`). That does not provide a distinct EntrySection
or shared curb for each separated carriageway.
Result: directional/source identity is a good starting point, but no single
pure structure resolver is authoritative for compiler and solver. Do not make
the 20-degree threshold the `JunctionBuildPlan` grouping rule.
### 2. Distance semantics mix along-line and radial projection
- Ordinary cutback uses `pointAlongLine()` and a tangent at that cutback
(`native-road.js:2844-2859`, `:2900-2918`), which is the correct local basis
for a bent ordinary approach.
- Complex geometry takes the first-segment heading at the node
(`complex-junction.js:42-44`) and maps a radius to an along-line station by a
scalar projection (`:857-861`). For a curve, that is not the intersection of
the centre-radius boundary and the line. `armEnvelopeAtRadius()` and corner
calculations reuse it (`:862-878`, `:919-934`).
- External road surface has a late per-road radial correction
(`native-road.js:656-699`, `:3215-3236`), but the other consumers do not all
receive that same per-road radius.
Result: `EntrySection` must name a fixed far section and a station measured on
the source polyline. It may derive a boundary intersection from the actual
polyline, but may not equate that with a centre projection.
### 3. Existing surfaces have no shared-boundary authority
- Complex geometry independently emits a core polygon (`complex-junction.js:551-602`), one rectangular polygon per carriageway (`:603-631`), corner fills
(`:450-490`), pedestrian corner bands (`:492-549`), and automatic corner
islands/crossings (`:319-449`). Their overlap is intentional in places; it is
not a referenced seam contract.
- Ordinary boundaries merge parallel approaches into a single face
(`native-road.js:2861-2897`) and then independently round corners
(`:2900-2955`). This avoids one failure mode but loses separate-corridor
semantics.
- `roadRing()` and `sidewalkRing()` only offset independent centre lines
(`native-road.js:3364-3396`); neither receives a shared boundary reference.
- Validation is local: complex pedestrian corners check self-intersection
(`complex-junction.js:519-530`) and the core checks one ring (`:565-566`).
There is no validation of road/core seams, connected required pavement, holes,
or exclusion zones.
Result: phase 2 needs `BoundaryGraph` ownership before adding more controls.
Core, approach, corner, sidewalk, marking, and facility producers must consume
edge references rather than reconstructing offset rectangles.
### 4. Layer trimming is inconsistent
| Consumer | Complex-cluster trim path | Per-carriageway boundary radius |
| --- | --- | --- |
| Road surface | `native-road.js:688-699` | Yes, from `complexApproachBoundaryRadii()` |
| Edge lines | `native-road.js:1098-1120` | No |
| Centre/lane separators | `native-road.js:1171-1192` | No |
| Sidewalk strips | `native-road.js:1850-1855` | No |
| Lane centre lines | `native-road.js:2109-2140` | No |
| Complex carriageway, core, corners, facilities | `complex-junction.js:149-667` | Separate radial/core rules |
The shared helper falls back to `approachOuterRadius` when no radius is passed
(`native-road.js:3201-3212`). Thus the earlier road-surface continuity repair
does not establish a cross-layer contract. Every listed consumer must eventually
take its termination from the same `EntrySection`/BoundaryGraph plan.
### 5. Solver purity is currently violated indirectly
`direct-edit-solver.js:17` imports `complexJunctionMetrics()`. That function
calls `readReferenceCalibration()` (`complex-junction.js:740-757`), which uses
`fs.existsSync` and `fs.readFileSync` (`:723-737`). This conflicts with the
direct-edit resolver purity requirement in `.trellis/spec/backend/direct-edit-api.md`.
Preload reference-derived metrics in the compile/service boundary, then pass
plain values into a pure topology/plan resolver.
## Minimal counterexamples and required future invariants
| Fixture | Current baseline | Required plan invariant |
| --- | --- | --- |
| `divided` | Two 10 m-separated, same-heading carriageways become one 20-degree arm. | Two stable carriageways and EntrySections remain distinct; an arm may group them for presentation only. Their boundaries cannot collapse into a single solid approach unless an explicit traversable connection says so. |
| `tee` | Shape is `t-junction`; no closure or boundary object exists. | The blocked side is represented by explicit boundary edges, with no invented through pavement or facility. |
| `offset-unequal` | Label is `offset-cross`; widths remain approach metadata without boundary references. | Each section keeps its own position, tangent, left/right edge, and far anchor; generated rings have shared seams within 1 cm. |
| `curved-short` | Heading samples the first segment and core/radius code uses a projection-derived station; length is below the minimum core radius. | Resolve against actual polyline length and local tangent. Return an object-scoped unsupported diagnostic when a required transition cannot fit; never extend or silently disconnect geometry. |
## Recommended first implementation slice
Implement a pure `junction-build-plan` module before touching rendering or UI.
It should receive already-loaded model/config data and return either:
1. `JunctionBuildPlan` with version, source topology, stable carriageway keys,
`EntrySection`s (source polyline, far station, entry station, tangent,
left/right boundary endpoints), grouping provenance, and diagnostics; or
2. an object-scoped unsupported/ambiguous result with no geometry claim.
The module must be the sole source for both `resolveComplexJunctionTopology()`
and solver cluster handle anchors. First tests should make all four fixtures
positive: input order and rotation stable, separated carriageways retained,
curved stations bounded by actual length, and T closure explicit. Do not add a
new user control until phase 2 verifies shared seams and all layer consumers use
the plan.
## Compatibility matrix for the first slice
| Existing concept | First-slice treatment |
| --- | --- |
| Stable carriageway/arm/corner keys | Preserve source-derived keys; add plan-local keys without coordinate ordering. |
| `cluster-carriageway-width` and cutback | Read existing constraints through an adapter; retain values only when the resolved EntrySection has a feasible range, otherwise mark recheck/stale. |
| Corner radius | Preserve as a compatibility request, but do not derive a final curve until BoundaryGraph feasibility exists. |
| Crossing and stop-line offsets | Keep document readability; mark as dependent on an arm/section plan and do not create a facility from angle alone. |
| Ordinary junction output | No behavior change in the first slice. |
| Reference-file calibration | Move I/O outside the pure resolver and inject resolved metrics. |
## Checks run
`node test/junction-build-plan-counterexamples.js`
This is a planning-stage baseline and is intentionally not added to `npm test`
until phase 1 replaces its current-state assertions with the new plan contract.
@@ -0,0 +1,12 @@
// Run from repository root with BASELINE_ROOT pointing to a checkout of 6a8f026 with dependencies.
const fs=require('fs'),assert=require('assert/strict'),{performance}=require('perf_hooks');
const root=process.cwd(), old=require(process.env.BASELINE_ROOT+'/src/compile/native-road'),fast=require(root+'/src/compile/native-road');
const solveOld=require(process.env.BASELINE_ROOT+'/src/compile/direct-edit-solver').resolveDirectEditConstraints,solveFast=require(root+'/src/compile/direct-edit-solver').resolveDirectEditConstraints;
const dir=root+'/workbench-data/import-fE8XI7',options=JSON.parse(fs.readFileSync(dir+'/active/area-config.snapshot.json')).options,overrides=old.loadOverrides(dir+'/native-road-overrides.json'),model=old.compileRoadModel(fs.readFileSync(dir+'/source.osm','utf8'),overrides),doc=JSON.parse(fs.readFileSync(dir+'/active/native-road-edits.json'));
const context={junctionTemplates:options.junctionTemplates,selection:{type:'cluster',id:options.junctionTemplates.clusters[0].id}};
const handles=solveOld(model,doc,context).handles.handles;
const fields={'cluster-carriageway-width':'widthMeters','cluster-carriageway-transition-length':'transitionLengthMeters','cluster-carriageway-direction':'offsetDegrees','cluster-carriageway-position':'offsetMeters','cluster-corner-radius':'radiusMeters','cluster-crossing-inset':'insetMeters','cluster-stop-line-offset':'offsetMeters'};
const cases=[{name:'baseline',doc}];
for(const [kind,field] of Object.entries(fields)) {const h=handles.find(h=>h.kind===kind);if(!h){console.log(JSON.stringify({missing:kind}));continue;} cases.push({name:kind,doc:{...doc,constraints:[{id:'experiment',kind,anchor:h.anchor,value:{[field]:Math.min(h.value.max,h.value.current+0.4)},enabled:true,status:'exact'}]}});}
function run(native,solve,document){const t=performance.now(),resolution=solve(model,document,context),compiled=native.compileGeometry(model,overrides,{...options,directEdit:resolution});return {ms:performance.now()-t,resolution,compiled};}
for(let i=0;i<3;i++)for(const c of cases){const a=run(old,solveOld,c.doc),b=run(fast,solveFast,c.doc);assert.deepEqual(b.resolution,a.resolution);assert.deepEqual(b.compiled,a.compiled);if(c.name!=='baseline')assert.equal(a.resolution.constraintStates[0].applied,true,c.name);console.log(JSON.stringify({round:i,kind:c.name,oldMs:a.ms,newMs:b.ms,equal:true}));}
@@ -0,0 +1,31 @@
# JunctionTools preview latency audit — 2026-09-14
Investigation only; implementation unchanged. Baseline commit 6a8f026. Real source/config: workbench-data/import-fE8XI7, four-node cluster, radius 21m. Called exported editPreview with selection={cluster:actualClusterId}, no added constraints; this measures repeated preview processing, not actual browser input-to-paint latency. No writes to user workspace data. Performance wrappers in /private/tmp/profile-junction-preview.js instrument exported model/solver/compiler/projection stages before server import.
## Measurements
CPU-profiled run: 1 cold + 5 repeated calls. Then independent unprofiled process: 1 cold + 2 repeated calls. Unprofiled repeated values:
| Phase | Run 1 ms | Run 2 ms |
| --- | ---: | ---: |
| OSM/model build | 66.8 | 73.7 |
| Constraint resolution + handle construction | 306.3 | 313.1 |
| Whole-area geometry | 1996.8 | 1951.3 |
| Selected junction projection | 0.83 | 0.56 |
| Total editPreview | 2375.9 | 2344.7 |
| JSON.stringify response | 175.8 | 167.1 |
Response: 24,185,780 UTF-8 bytes. Counts include 20,942 lane-separator features (13.59MB), 4,978 direction-arrow features (4.24MB), 860 connectors (3.28MB), 2,212 center-line features (1.88MB). These are whole-region collections, not just the selected cluster. This already costs about 2.5 seconds before network/browser parsing/rendering. Small sample; do not label this P95.
CPU sampling across six selected-cluster previews: compileLaneMarkings inclusive ~7.1s, trimLineBeforeFirstControl inclusive ~6.8s (nested, do not sum); compileConnectors ~2.4s; resolver ~1.5s. The biggest hotspot is control avoidance, not core filling or four-island geometry. trimLineBeforeFirstControl probes every 0.25m and ringsOverlapControl scans control features; controlBounds alone consumes ~2.35s self time across six calls. Road/junction affects construction repeatedly scans global connections. Arrow assets are synchronously reread via loadManifest during generation.
## Confirmed causes
1. compileEditCandidate rereads/parses OSM and rebuilds the model, resolves constraints and compiles all area geometry for every request. selection reaches handle filtering; it does not restrict geometry compilation.
2. resolveDirectEditConstraints constructs all road/junction/cluster/lane handles before selectHandles filters them. Cluster selection does not avoid global handle/affects construction.
3. editPreview returns full-area layers. localJunctionPreview filters them only after browser receipt. Server JSON response is not compressed by sendJson; stringify is synchronous.
4. UI schedules live changes with 80ms trailing debounce; settle flushes immediately. AbortController abandons requests on the client, but synchronous server computation has no cancellation signal or cooperative yields, so obsolete work can still occupy the single event loop.
5. EditPreviewLayer.show clears touched sources, reparses GeoJSON, recreates features and reprojects to EPSG:3857. JunctionTools does scope its displayed collections, so do not claim it necessarily draws all ~30,000 features. Browser parsing/filtering/paint duration has not been measured.
6. degraded only labels compute >300ms. It neither stops computation nor includes response serialization/network/paint. Historical comments about ~142ms reflect different data/code and are not current performance evidence.
Priority implied by evidence: avoid whole-area marking/control recomputation; generate selected handles before filtering; return scoped layers; cache stable parsing/assets. Do not promise 300ms from debounce tweaks, worker offloading alone, or merely adding Maps. Backend computation alone must be reduced by roughly an order of magnitude.
@@ -0,0 +1,3 @@
{"run":0,"computeMs":1564.985023,"stages":{"compileRoadModel":79.877753,"resolveDirectEditConstraints":28.894586000000004,"compileGeometry":1445.833637,"projectJunctionStructure":1.6543349999999464,"standardsDiagnostics":0.2963159999999334},"serializationMs":233.65626299999985,"bytes":24185780,"degraded":true,"layerBytes":{"roadSurface":259256,"edgeLines":42,"sidewalkSurface":22768,"intersectionSurface":151764,"laneCenterlines":285839,"laneSeparators":13587441,"centerLines":1875036,"directionArrows":4243365,"turnArrows":42,"crosswalks":256167,"vehicleStopLines":5999,"connectors":3278237},"counts":{"roadSurface":239,"edgeLines":0,"sidewalkSurface":8,"intersectionSurface":92,"laneCenterlines":499,"laneSeparators":20942,"centerLines":2212,"directionArrows":4978,"turnArrows":0,"crosswalks":141,"vehicleStopLines":4,"connectors":860}}
{"run":1,"computeMs":1451.9432230000002,"stages":{"compileRoadModel":68.01373799999965,"resolveDirectEditConstraints":10.46456900000021,"compileGeometry":1367.673898,"projectJunctionStructure":0.9491409999995994,"standardsDiagnostics":0.021730999999817868},"serializationMs":171.42120999999997,"bytes":24185780,"degraded":true,"layerBytes":{"roadSurface":259256,"edgeLines":42,"sidewalkSurface":22768,"intersectionSurface":151764,"laneCenterlines":285839,"laneSeparators":13587441,"centerLines":1875036,"directionArrows":4243365,"turnArrows":42,"crosswalks":256167,"vehicleStopLines":5999,"connectors":3278237},"counts":{"roadSurface":239,"edgeLines":0,"sidewalkSurface":8,"intersectionSurface":92,"laneCenterlines":499,"laneSeparators":20942,"centerLines":2212,"directionArrows":4978,"turnArrows":0,"crosswalks":141,"vehicleStopLines":4,"connectors":860}}
{"run":2,"computeMs":1387.485408,"stages":{"compileRoadModel":71.12653100000034,"resolveDirectEditConstraints":7.21379799999977,"compileGeometry":1302.8253790000003,"projectJunctionStructure":0.6795459999993909,"standardsDiagnostics":0.2227179999999862},"serializationMs":168.53626499999973,"bytes":24185780,"degraded":true,"layerBytes":{"roadSurface":259256,"edgeLines":42,"sidewalkSurface":22768,"intersectionSurface":151764,"laneCenterlines":285839,"laneSeparators":13587441,"centerLines":1875036,"directionArrows":4243365,"turnArrows":42,"crosswalks":256167,"vehicleStopLines":5999,"connectors":3278237},"counts":{"roadSurface":239,"edgeLines":0,"sidewalkSurface":8,"intersectionSurface":92,"laneCenterlines":499,"laneSeparators":20942,"centerLines":2212,"directionArrows":4978,"turnArrows":0,"crosswalks":141,"vehicleStopLines":4,"connectors":860}}
@@ -0,0 +1,22 @@
{"missing":"cluster-crossing-inset"}
{"round":0,"kind":"baseline","oldMs":2285.4365359999997,"newMs":1292.1180959999997,"equal":true}
{"round":0,"kind":"cluster-carriageway-width","oldMs":2376.678916,"newMs":1238.5497850000002,"equal":true}
{"round":0,"kind":"cluster-carriageway-transition-length","oldMs":2178.8894229999987,"newMs":1192.483655,"equal":true}
{"round":0,"kind":"cluster-carriageway-direction","oldMs":2180.4383500000004,"newMs":1218.5936649999985,"equal":true}
{"round":0,"kind":"cluster-carriageway-position","oldMs":2216.8962889999984,"newMs":1221.5325800000028,"equal":true}
{"round":0,"kind":"cluster-corner-radius","oldMs":2166.0852030000024,"newMs":1209.366739000001,"equal":true}
{"round":0,"kind":"cluster-stop-line-offset","oldMs":2255.1596759999993,"newMs":1192.0639980000014,"equal":true}
{"round":1,"kind":"baseline","oldMs":2172.251967,"newMs":1182.4069149999996,"equal":true}
{"round":1,"kind":"cluster-carriageway-width","oldMs":2199.3163970000023,"newMs":1198.1523030000026,"equal":true}
{"round":1,"kind":"cluster-carriageway-transition-length","oldMs":2240.4705299999987,"newMs":1194.0498739999966,"equal":true}
{"round":1,"kind":"cluster-carriageway-direction","oldMs":2180.7153689999977,"newMs":1188.6622540000026,"equal":true}
{"round":1,"kind":"cluster-carriageway-position","oldMs":2172.935529000002,"newMs":1196.8491980000035,"equal":true}
{"round":1,"kind":"cluster-corner-radius","oldMs":2219.6554370000013,"newMs":1189.8391730000003,"equal":true}
{"round":1,"kind":"cluster-stop-line-offset","oldMs":2100.577357999995,"newMs":1227.7292689999958,"equal":true}
{"round":2,"kind":"baseline","oldMs":2165.955930999997,"newMs":1179.9063920000044,"equal":true}
{"round":2,"kind":"cluster-carriageway-width","oldMs":2210.4734150000004,"newMs":1202.4629229999991,"equal":true}
{"round":2,"kind":"cluster-carriageway-transition-length","oldMs":2111.6621700000032,"newMs":1153.514052999999,"equal":true}
{"round":2,"kind":"cluster-carriageway-direction","oldMs":2172.6889870000014,"newMs":1251.9535700000051,"equal":true}
{"round":2,"kind":"cluster-carriageway-position","oldMs":2256.1194470000046,"newMs":1234.4344730000012,"equal":true}
{"round":2,"kind":"cluster-corner-radius","oldMs":2239.5719339999923,"newMs":1189.8456850000075,"equal":true}
{"round":2,"kind":"cluster-stop-line-offset","oldMs":2228.122657,"newMs":1212.329448999997,"equal":true}
@@ -0,0 +1,81 @@
// Isolated experiment: invokes production pure functions; never writes active data.
// Run from repository root: node .trellis/tasks/09-08-junction-reference-fidelity/research/preview-scope-experiment.cjs
const fs = require('fs');
const { performance } = require('perf_hooks');
const { createHash } = require('crypto');
const { compileRoadModel, compileGeometry, loadOverrides } = require(process.cwd() + '/src/compile/native-road');
const { resolveDirectEditConstraints } = require(process.cwd() + '/src/compile/direct-edit-solver');
const dir = 'workbench-data/import-fE8XI7';
const start = performance.now();
const options = JSON.parse(fs.readFileSync(dir + '/active/area-config.snapshot.json')).options;
const overrides = loadOverrides(dir + '/native-road-overrides.json');
const model = compileRoadModel(fs.readFileSync(dir + '/source.osm', 'utf8'), overrides);
const document = JSON.parse(fs.readFileSync(dir + '/active/native-road-edits.json'));
const cluster = options.junctionTemplates.clusters[0];
const context = { junctionTemplates: options.junctionTemplates, selection: { type: 'cluster', id: cluster.id } };
const byNode = new Map();
for (const e of model.endpoints) { if (!byNode.has(e.nodeId)) byNode.set(e.nodeId, new Set()); byNode.get(e.nodeId).add(e.roadId); }
function scope(depth) {
const nodes = new Set(cluster.nodeIds), roads = new Set();
for (let i = 0; i <= depth; i++) {
for (const node of nodes) for (const id of byNode.get(node) || []) roads.add(id);
for (const e of model.endpoints) if (roads.has(e.roadId)) nodes.add(e.nodeId);
}
const endpoints = model.endpoints.filter(e => roads.has(e.roadId));
const ids = new Set(endpoints.map(e => e.id));
return { ...model, roads: model.roads.filter(r => roads.has(r.id)), endpoints,
connections: model.connections.filter(c => ids.has(c.fromEndpointId) && ids.has(c.toEndpointId)) };
}
function run(m, doc) {
const t = performance.now();
const resolution = resolveDirectEditConstraints(m, doc, context);
const solved = performance.now();
const compiled = compileGeometry(m, overrides, { ...options, directEdit: resolution });
const end = performance.now();
return { compiled, resolution, solveMs: solved-t, compileMs: end-solved, computeMs: end-t };
}
function features(compiled) {
const map = new Map();
for (const [layer, collection] of Object.entries(compiled)) for (const f of collection?.features || []) {
const json = JSON.stringify(f), hash = createHash('sha256').update(json).digest('hex');
const key = layer + ':' + hash;
const old = map.get(key); map.set(key, { count: (old?.count || 0)+1, layer, feature: f });
}
return map;
}
function delta(before, after) {
const result = new Map();
for (const key of new Set([...before.keys(), ...after.keys()])) {
const count = (after.get(key)?.count || 0)-(before.get(key)?.count || 0);
if (count) result.set(key, { ...(after.get(key) || before.get(key)), count });
}
return result;
}
function compare(a,b) {
const mismatches=[];
for(const key of new Set([...a.keys(),...b.keys()])) if(a.get(key)?.count !== b.get(key)?.count) {
const f=a.get(key)||b.get(key); mismatches.push({layer:f.layer,id:f.feature.properties?.native_id,full:a.get(key)?.count||0,local:b.get(key)?.count||0});
}
return {equal:!mismatches.length,mismatchCount:mismatches.length,examples:mismatches.slice(0,8)};
}
const setupMs=performance.now()-start;
const fullBase=run(model,document), fullFeatures=features(fullBase.compiled);
const handle=fullBase.resolution.handles.handles.find(h=>h.kind==='cluster-carriageway-width');
if(!handle) throw Error('Missing width handle');
const scopes=[0,1,2].map(depth=>{const m=scope(depth), base=run(m,document);return {depth,m,base:features(base.compiled),rows:[]};});
console.log(JSON.stringify({setupMs,fullRoads:model.roads.length,scopes:scopes.map(s=>({depth:s.depth,roads:s.m.roads.length})),handle:handle.handleId}));
for(let i=0;i<20;i++) {
const value=handle.value.current + 0.1 + (i%10)*0.1;
const doc={...document,constraints:[...document.constraints,{id:'experiment-width',kind:handle.kind,anchor:handle.anchor,value:{widthMeters:value},enabled:true,status:'exact'}]};
const full=run(model,doc);
if(!full.resolution.constraintStates.find(s=>s.constraintId==='experiment-width')?.applied) throw Error('Edit not applied: '+JSON.stringify(full.resolution.constraintStates));
const reference=delta(fullFeatures,features(full.compiled));
for(const s of scopes) {
const local=run(s.m,doc), diff=delta(s.base,features(local.compiled));
const t=performance.now();const payload=JSON.stringify({changes:[...diff.values()],handles:local.resolution.handles,constraintStates:local.resolution.constraintStates});const serializationMs=performance.now()-t;
const row={run:i,value,depth:s.depth,solveMs:local.solveMs,compileMs:local.compileMs,computeMs:local.computeMs,serializationMs,bytes:Buffer.byteLength(payload),fullComputeMs:full.computeMs,changed:reference.size,comparison:compare(reference,diff)};
s.rows.push(row);console.log(JSON.stringify(row));
}
}
function stats(values){const s=[...values].sort((a,b)=>a-b);return {min:s[0],median:s[Math.floor(s.length/2)],p95:s[Math.ceil(s.length*.95)-1],max:s.at(-1)};}
console.log(JSON.stringify({summary:scopes.map(s=>({depth:s.depth,roads:s.m.roads.length,allDeltasEqual:s.rows.every(r=>r.comparison.equal),computeAndSerializationMs:stats(s.rows.map(r=>r.computeMs+r.serializationMs)),fullComputeMs:stats(s.rows.map(r=>r.fullComputeMs)),bytes:stats(s.rows.map(r=>r.bytes))}))}));
@@ -0,0 +1,62 @@
{"setupMs":82.091327,"fullRoads":318,"scopes":[{"depth":0,"roads":12},{"depth":1,"roads":32},{"depth":2,"roads":56}],"handle":"handle:cluster-carriageway-width:cluster:cluster-8005332807:carriageway:8005332807/segment%3Away%2F253970456%2F1/road%3Away%2F253970456%3Asegment%2F1%3Aforward"}
{"run":0,"value":9.85,"depth":0,"solveMs":9.557064999999966,"compileMs":316.0986899999998,"computeMs":325.6557549999998,"serializationMs":2.232861000000412,"bytes":416605,"fullComputeMs":2170.9019529999996,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":0,"value":9.85,"depth":1,"solveMs":15.14473100000032,"compileMs":420.10305100000005,"computeMs":435.24778200000037,"serializationMs":2.4457000000002154,"bytes":418680,"fullComputeMs":2170.9019529999996,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":0,"value":9.85,"depth":2,"solveMs":21.637515999999778,"compileMs":547.5551640000003,"computeMs":569.1926800000001,"serializationMs":2.4221150000003036,"bytes":420460,"fullComputeMs":2170.9019529999996,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":1,"value":9.95,"depth":0,"solveMs":10.689680999999837,"compileMs":360.28462200000104,"computeMs":370.9743030000009,"serializationMs":1.907219000000623,"bytes":436363,"fullComputeMs":2162.349112,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":1,"value":9.95,"depth":1,"solveMs":13.274993000000904,"compileMs":432.1202119999998,"computeMs":445.3952050000007,"serializationMs":1.9363740000007965,"bytes":438438,"fullComputeMs":2162.349112,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":1,"value":9.95,"depth":2,"solveMs":20.685750000000553,"compileMs":569.7800330000009,"computeMs":590.4657830000015,"serializationMs":2.0177759999987757,"bytes":440218,"fullComputeMs":2162.349112,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":2,"value":10.049999999999999,"depth":0,"solveMs":5.940107000000353,"compileMs":319.55948499999977,"computeMs":325.4995920000001,"serializationMs":1.9293809999999212,"bytes":436351,"fullComputeMs":2111.5045450000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":2,"value":10.049999999999999,"depth":1,"solveMs":11.450167999999394,"compileMs":419.90083100000084,"computeMs":431.35099900000023,"serializationMs":2.2531980000003387,"bytes":438426,"fullComputeMs":2111.5045450000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":2,"value":10.049999999999999,"depth":2,"solveMs":20.372020999999222,"compileMs":547.839258,"computeMs":568.2112789999992,"serializationMs":2.001905999999508,"bytes":440206,"fullComputeMs":2111.5045450000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":3,"value":10.15,"depth":0,"solveMs":10.110854999998992,"compileMs":320.47782700000243,"computeMs":330.5886820000014,"serializationMs":1.9960460000002058,"bytes":436259,"fullComputeMs":2118.175674,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":3,"value":10.15,"depth":1,"solveMs":13.607135999998718,"compileMs":426.9146929999988,"computeMs":440.5218289999975,"serializationMs":2.1548540000003413,"bytes":438334,"fullComputeMs":2118.175674,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":3,"value":10.15,"depth":2,"solveMs":20.650824000000284,"compileMs":556.8770189999996,"computeMs":577.5278429999998,"serializationMs":1.9438280000031227,"bytes":440114,"fullComputeMs":2118.175674,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":4,"value":10.25,"depth":0,"solveMs":10.683538999997836,"compileMs":333.69013300000006,"computeMs":344.3736719999979,"serializationMs":2.4758959999999206,"bytes":436166,"fullComputeMs":2192.3786870000004,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":4,"value":10.25,"depth":1,"solveMs":13.00734999999986,"compileMs":447.440462999999,"computeMs":460.44781299999886,"serializationMs":2.4687530000010156,"bytes":438241,"fullComputeMs":2192.3786870000004,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":4,"value":10.25,"depth":2,"solveMs":22.45761499999935,"compileMs":601.8785310000021,"computeMs":624.3361460000015,"serializationMs":1.9048550000006799,"bytes":440021,"fullComputeMs":2192.3786870000004,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":5,"value":10.35,"depth":0,"solveMs":9.755558000000747,"compileMs":319.6855399999986,"computeMs":329.44109799999933,"serializationMs":1.9265759999980219,"bytes":434742,"fullComputeMs":2132.4120299999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":5,"value":10.35,"depth":1,"solveMs":13.406458999997994,"compileMs":424.9514990000025,"computeMs":438.3579580000005,"serializationMs":2.099941000000399,"bytes":436817,"fullComputeMs":2132.4120299999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":5,"value":10.35,"depth":2,"solveMs":23.12702100000024,"compileMs":567.2923549999978,"computeMs":590.419375999998,"serializationMs":1.9414530000030936,"bytes":438597,"fullComputeMs":2132.4120299999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":6,"value":10.45,"depth":0,"solveMs":5.993077000002813,"compileMs":330.5428659999998,"computeMs":336.5359430000026,"serializationMs":1.8765419999981532,"bytes":434706,"fullComputeMs":2136.052312,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":6,"value":10.45,"depth":1,"solveMs":13.188781000000745,"compileMs":430.75614199999836,"computeMs":443.9449229999991,"serializationMs":2.0286569999989297,"bytes":436781,"fullComputeMs":2136.052312,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":6,"value":10.45,"depth":2,"solveMs":20.827565999999933,"compileMs":568.7115779999986,"computeMs":589.5391439999985,"serializationMs":1.88463700000284,"bytes":438561,"fullComputeMs":2136.052312,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":7,"value":10.549999999999999,"depth":0,"solveMs":5.932803999996395,"compileMs":324.9480270000058,"computeMs":330.8808310000022,"serializationMs":1.9272359999959008,"bytes":434902,"fullComputeMs":2138.8442920000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":7,"value":10.549999999999999,"depth":1,"solveMs":10.703045999995084,"compileMs":441.81436500000564,"computeMs":452.5174110000007,"serializationMs":1.9678730000014184,"bytes":436977,"fullComputeMs":2138.8442920000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":7,"value":10.549999999999999,"depth":2,"solveMs":19.830455000002985,"compileMs":554.1457620000001,"computeMs":573.9762170000031,"serializationMs":1.9632649999985006,"bytes":438757,"fullComputeMs":2138.8442920000016,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":8,"value":10.65,"depth":0,"solveMs":5.800204999999551,"compileMs":319.26163500000257,"computeMs":325.0618400000021,"serializationMs":1.8717019999967306,"bytes":434769,"fullComputeMs":2196.7264460000006,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":8,"value":10.65,"depth":1,"solveMs":11.240945999998075,"compileMs":433.28231299999607,"computeMs":444.52325899999414,"serializationMs":1.9364040000000386,"bytes":436844,"fullComputeMs":2196.7264460000006,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":8,"value":10.65,"depth":2,"solveMs":20.785486999993736,"compileMs":547.6380000000063,"computeMs":568.423487,"serializationMs":1.9342800000013085,"bytes":438624,"fullComputeMs":2196.7264460000006,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":9,"value":10.75,"depth":0,"solveMs":10.293267000000924,"compileMs":316.29617999999755,"computeMs":326.5894469999985,"serializationMs":2.127483000003849,"bytes":443410,"fullComputeMs":2147.80616,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":9,"value":10.75,"depth":1,"solveMs":13.12561299999652,"compileMs":431.6866379999992,"computeMs":444.81225099999574,"serializationMs":1.9623530000026221,"bytes":445485,"fullComputeMs":2147.80616,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":9,"value":10.75,"depth":2,"solveMs":21.711364999995567,"compileMs":562.7895540000027,"computeMs":584.5009189999982,"serializationMs":2.3710900000005495,"bytes":447265,"fullComputeMs":2147.80616,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":10,"value":9.85,"depth":0,"solveMs":5.973549999995157,"compileMs":370.3468350000039,"computeMs":376.3203849999991,"serializationMs":1.7907410000043456,"bytes":416605,"fullComputeMs":2151.4998820000037,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":10,"value":9.85,"depth":1,"solveMs":15.134751999998116,"compileMs":439.9024070000014,"computeMs":455.0371589999995,"serializationMs":2.082798000003095,"bytes":418680,"fullComputeMs":2151.4998820000037,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":10,"value":9.85,"depth":2,"solveMs":20.18708400000469,"compileMs":631.2939239999978,"computeMs":651.4810080000025,"serializationMs":1.8393819999982952,"bytes":420460,"fullComputeMs":2151.4998820000037,"changed":124,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":11,"value":9.95,"depth":0,"solveMs":6.066925999999512,"compileMs":381.1988300000012,"computeMs":387.2657560000007,"serializationMs":2.6824540000015986,"bytes":436363,"fullComputeMs":2601.729800000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":11,"value":9.95,"depth":1,"solveMs":13.36330799999996,"compileMs":463.12375500000053,"computeMs":476.4870630000005,"serializationMs":2.1306079999994836,"bytes":438438,"fullComputeMs":2601.729800000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":11,"value":9.95,"depth":2,"solveMs":20.543462999994517,"compileMs":629.755717,"computeMs":650.2991799999945,"serializationMs":1.9414929999984452,"bytes":440218,"fullComputeMs":2601.729800000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":12,"value":10.049999999999999,"depth":0,"solveMs":6.153537999998662,"compileMs":331.8629030000011,"computeMs":338.01644099999976,"serializationMs":1.9528450000070734,"bytes":436351,"fullComputeMs":2191.8486420000045,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":12,"value":10.049999999999999,"depth":1,"solveMs":13.674271999996563,"compileMs":443.1867110000021,"computeMs":456.86098299999867,"serializationMs":3.3135089999996126,"bytes":438426,"fullComputeMs":2191.8486420000045,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":12,"value":10.049999999999999,"depth":2,"solveMs":23.825622000003932,"compileMs":574.9863939999996,"computeMs":598.8120160000035,"serializationMs":1.9795050000029732,"bytes":440206,"fullComputeMs":2191.8486420000045,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":13,"value":10.15,"depth":0,"solveMs":7.467855000002601,"compileMs":437.9851589999962,"computeMs":445.4530139999988,"serializationMs":3.034705000005488,"bytes":436259,"fullComputeMs":2208.0030289999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":13,"value":10.15,"depth":1,"solveMs":12.341310999996495,"compileMs":426.7040380000035,"computeMs":439.045349,"serializationMs":2.0565389999974286,"bytes":438334,"fullComputeMs":2208.0030289999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":13,"value":10.15,"depth":2,"solveMs":19.955190000000584,"compileMs":561.6838289999941,"computeMs":581.6390189999947,"serializationMs":2.0973060000033,"bytes":440114,"fullComputeMs":2208.0030289999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":14,"value":10.25,"depth":0,"solveMs":6.05423200000223,"compileMs":368.2168679999959,"computeMs":374.2710999999981,"serializationMs":2.1724969999995665,"bytes":436166,"fullComputeMs":2215.618040000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":14,"value":10.25,"depth":1,"solveMs":14.679307999998855,"compileMs":448.27351700000145,"computeMs":462.9528250000003,"serializationMs":1.9932710000066436,"bytes":438241,"fullComputeMs":2215.618040000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":14,"value":10.25,"depth":2,"solveMs":21.605415999998513,"compileMs":611.7472209999978,"computeMs":633.3526369999963,"serializationMs":1.9718310000025667,"bytes":440021,"fullComputeMs":2215.618040000001,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":15,"value":10.35,"depth":0,"solveMs":5.86444499999925,"compileMs":473.06164600000193,"computeMs":478.9260910000012,"serializationMs":3.323868000006769,"bytes":434742,"fullComputeMs":2201.9000949999972,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":15,"value":10.35,"depth":1,"solveMs":18.427781999998842,"compileMs":555.6714759999886,"computeMs":574.0992579999875,"serializationMs":2.3020499999984168,"bytes":436817,"fullComputeMs":2201.9000949999972,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":15,"value":10.35,"depth":2,"solveMs":20.98601300000155,"compileMs":609.2047100000054,"computeMs":630.190723000007,"serializationMs":3.538220000002184,"bytes":438597,"fullComputeMs":2201.9000949999972,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":16,"value":10.45,"depth":0,"solveMs":13.330818000002182,"compileMs":322.76873599999817,"computeMs":336.09955400000035,"serializationMs":2.1809229999926174,"bytes":434706,"fullComputeMs":2265.4950020000106,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":16,"value":10.45,"depth":1,"solveMs":12.398257000008016,"compileMs":437.89218399999663,"computeMs":450.29044100000465,"serializationMs":2.5593230000085896,"bytes":436781,"fullComputeMs":2265.4950020000106,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":16,"value":10.45,"depth":2,"solveMs":21.088917000000947,"compileMs":569.1401420000038,"computeMs":590.2290590000048,"serializationMs":1.9589859999978216,"bytes":438561,"fullComputeMs":2265.4950020000106,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":17,"value":10.549999999999999,"depth":0,"solveMs":14.146958999990602,"compileMs":340.1923450000031,"computeMs":354.3393039999937,"serializationMs":3.6743449999921722,"bytes":434902,"fullComputeMs":2297.191955999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":17,"value":10.549999999999999,"depth":1,"solveMs":18.01058900001226,"compileMs":500.56653299999016,"computeMs":518.5771220000024,"serializationMs":2.0068260000116425,"bytes":436977,"fullComputeMs":2297.191955999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":17,"value":10.549999999999999,"depth":2,"solveMs":20.03393700000015,"compileMs":564.0579949999956,"computeMs":584.0919319999957,"serializationMs":2.207872999992105,"bytes":438757,"fullComputeMs":2297.191955999995,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":18,"value":10.65,"depth":0,"solveMs":9.937007999993511,"compileMs":322.0552380000008,"computeMs":331.99224599999434,"serializationMs":1.876021000003675,"bytes":434769,"fullComputeMs":2154.9666179999913,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":18,"value":10.65,"depth":1,"solveMs":12.702348000006168,"compileMs":437.82925599999726,"computeMs":450.5316040000034,"serializationMs":1.9326770000043325,"bytes":436844,"fullComputeMs":2154.9666179999913,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":18,"value":10.65,"depth":2,"solveMs":23.21744100000069,"compileMs":827.8039559999888,"computeMs":851.0213969999895,"serializationMs":2.113415999992867,"bytes":438624,"fullComputeMs":2154.9666179999913,"changed":130,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":19,"value":10.75,"depth":0,"solveMs":6.400811999992584,"compileMs":328.2599120000086,"computeMs":334.6607240000012,"serializationMs":1.978984000001219,"bytes":443410,"fullComputeMs":2651.589730000007,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":19,"value":10.75,"depth":1,"solveMs":14.428186999997706,"compileMs":437.5252150000015,"computeMs":451.9534019999992,"serializationMs":2.0162639999907697,"bytes":445485,"fullComputeMs":2651.589730000007,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"run":19,"value":10.75,"depth":2,"solveMs":22.66500399999495,"compileMs":552.8812500000058,"computeMs":575.5462540000008,"serializationMs":2.03872599999886,"bytes":447265,"fullComputeMs":2651.589730000007,"changed":132,"comparison":{"equal":true,"mismatchCount":0,"examples":[]}}
{"summary":[{"depth":0,"roads":12,"allDeltasEqual":true,"computeAndSerializationMs":{"min":326.93354199999885,"median":338.41248500000074,"p95":448.4877190000043,"max":482.24995900000795},"fullComputeMs":{"min":2111.5045450000016,"median":2191.8486420000045,"p95":2601.729800000001,"max":2651.589730000007},"bytes":{"min":416605,"median":436166,"p95":443410,"max":443410}},{"depth":1,"roads":32,"allDeltasEqual":true,"computeAndSerializationMs":{"min":433.60419700000057,"median":452.84976400001324,"p95":520.5839480000141,"max":576.4013079999859},"fullComputeMs":{"min":2111.5045450000016,"median":2191.8486420000045,"p95":2601.729800000001,"max":2651.589730000007},"bytes":{"min":418680,"median":438241,"p95":445485,"max":445485}},{"depth":2,"roads":56,"allDeltasEqual":true,"computeAndSerializationMs":{"min":570.2131849999987,"median":592.1880450000026,"p95":653.3203900000008,"max":853.1348129999824},"fullComputeMs":{"min":2111.5045450000016,"median":2191.8486420000045,"p95":2601.729800000001,"max":2651.589730000007},"bytes":{"min":420460,"median":440021,"p95":447265,"max":447265}}]}
@@ -0,0 +1,31 @@
# 小范围预览优化(2026-09-14)
用户取消 300ms 硬门槛,要求明显提速、任务简洁、避免大改;正式修改前必须完成内部试验。
## 本次边界
先试验两处等价优化:
- direct-edit-solver.js:cluster selection 不构造最终必然被过滤掉的 road/junction/lane 手柄,所有约束仍完整求解。
- native-road.js:trimLineBeforeFirstControl 每条线建立按 minX 排序的碰撞候选包围盒,仍使用原精确 ringsOverlap、原采样步长和原裁切回退。
不接入子路网裁剪,不增加接口/客户端协议、跨请求缓存、版本失效机制或新依赖。模型缓存节省远小于标线裁切,本轮先减少扫描和无用派生计算,避免扩大状态管理风险。源数据、保存与正式编译契约保持原样。
验收:真实四节点/21m工作区,新旧完整 resolution 与 compiled 深比较;多类非空编辑确实 applied;现有几何与编辑回归;记录整接口计算和序列化耗时。若通过,可作为独立提交候选,用户复核后提交。
## 前序子路网试验
318条道路缩到12/32/56条,20次宽度调整的图层多重集合增删变化均一致。12条方案计算+序列化中位数338ms,样本P95 448ms;32条453ms;56条592ms。比较不包含非图层元数据,耗时不含增量提取与浏览器显示,尚不足以发布通用局部编译。因此仅保留研究,不纳入这次产品修改。
## 结果与正式实现
隔离原型完成 3 轮 × 7 场景,共 21 次新旧深比较:空文档、宽度、过渡长度、方向、位置、圆角、停止线。全部完整 resolution(含 Map、手柄、状态、诊断)与 compiled(全部图层及非图层产物)一致;所有非空编辑确实 applied。旧计算中位数 2199.3ms,新原型 1198.2ms。当前真实样本未发布 cluster-crossing-inset 手柄,未冒称该编辑参与此差分试验;已有设施回归另行通过。
试验通过后仅修改两个生产文件,增加一个完整求解结果不受手柄筛选影响的回归。生产实现与原型算法相同,只作格式和局部变量整理。
真实 editPreview 接口复测(独立运行,没有与测试并发):原先两次热运行计算+JSON序列化 2552/2512ms;优化后 1623/1556ms,平均下降约37%。模型解析仍68–71ms;resolver从306–313ms降至7–10ms;全量几何从1951–1997ms降至1303–1368ms。响应仍24,185,780字节。本报告不是浏览器输入到绘制完成延迟,未测网络和地图更新;3次接口样本不报告P95。
检查:新增求解器回归通过;npm test 前序全部代码、几何、编辑API、导入编译检查通过,最后 test/fixtures.js 仍是已有快照差异,未更新基线。首次沙箱内监听8899失败,取得工具批准后在沙箱外重跑得到上述结果。npm run test:client、npm run format:check、git diff --check 通过。无客户端改动,未重复E2E。
原始数据:preview-prototype-results.jsonl、preview-optimized-api.jsonl、preview-scope-results.jsonl。重跑差分:BASELINE_ROOT 指向6a8f026检出及其依赖,从当前仓库运行 node .trellis/tasks/09-08-junction-reference-fidelity/research/preview-equivalence-experiment.cjs。
本轮未提交。优化单元完成;父任务保持进行中。后续是否进一步缩短传输和渲染等待,应先测浏览器,不直接扩展本轮范围。