perf: cache bundled turn lane manifest
This commit is contained in:
1 parent
78c357e445
commit
82846cdebc
3 files changed
+25
-1
No files matched your search
@@ -192,3 +192,7 @@ npm test 中代码、投影、边界反例、设施、编辑与工作台导入
|
||||
## 2026-09-14 现有设施联动收口
|
||||
|
||||
现有设施范围的 A6 已由 `test/index.js`、`test/workbench-edit-api.js` 和 `test/junction-facility-composition.js` 覆盖:无 crossing 来源时复杂斑马线省略并发布 `complex-junction-crossing-source-missing`,停止线保留 `unknown-no-crossing-source`;匹配 OSM crossing 节点时发布带来源证据的斑马线;已知交通岛作为排除区域保留并纳入结构投影;角部设施缺少有效道路/步行连接时不伪造。导流岛自由编辑、新右转通道和全套过街设施编辑器仍按 PRD 留在后续任务。
|
||||
|
||||
## 2026-09-14 内置箭头资源清单缓存
|
||||
|
||||
预览编译重复读取固定的 `assets/lane-icons/manifest.json`。`loadManifest()` 现在只缓存内置清单,并以文件 `mtimeMs` 和大小失效;自定义清单路径保持每次读取,避免改变调用方的动态配置语义。默认清单缓存身份回归已加入 `test/index.js`。真实预览输出未改变;本轮样本总耗时受几何计算抖动影响,不能单独宣称可测的额外百分比收益。
|
||||
@@ -5,6 +5,7 @@ const path = require('path');
|
||||
const { laneCenterline } = require('../geometry/lane-geometry');
|
||||
|
||||
const ASSET_MANIFEST = path.resolve(__dirname, '..', '..', 'assets', 'lane-icons', 'manifest.json');
|
||||
let defaultManifestCache = null;
|
||||
const LANE_WIDTH_METERS = 3.2;
|
||||
const PLACEMENT_DISTANCE_METERS = 9;
|
||||
const SPATIAL_MATCH_MAX_DISTANCE_METERS = 18;
|
||||
@@ -15,7 +16,21 @@ const SPATIAL_MATCH_MIN_ALIGNMENT = Math.cos(Math.PI / 6);
|
||||
const SVG_METERS_PER_UNIT = 0.1;
|
||||
|
||||
function loadManifest(file = ASSET_MANIFEST) {
|
||||
const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
// The bundled manifest is immutable during normal compilation, so avoid
|
||||
// reparsing it for every road preview. Keep custom paths uncached because
|
||||
// callers may use them as a live test/config input.
|
||||
let manifest;
|
||||
if (file === ASSET_MANIFEST) {
|
||||
const stat = fs.statSync(file);
|
||||
if (
|
||||
defaultManifestCache &&
|
||||
defaultManifestCache.mtimeMs === stat.mtimeMs &&
|
||||
defaultManifestCache.size === stat.size
|
||||
)
|
||||
return defaultManifestCache.manifest;
|
||||
manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
defaultManifestCache = { manifest, mtimeMs: stat.mtimeMs, size: stat.size };
|
||||
} else manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
if (!Array.isArray(manifest.assets)) throw new Error('turn-lane asset manifest has no assets array');
|
||||
return manifest;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ const compiler = require('../src');
|
||||
assert.equal(typeof compiler.laneGeometry.laneCenterline, 'function');
|
||||
assert.equal(typeof compiler.gaodeReference.convertGeoJson, 'function');
|
||||
assert.equal(typeof compiler.turnLaneArrows.buildCustomTurnLaneArrows, 'function');
|
||||
assert.strictEqual(
|
||||
compiler.turnLaneArrows.loadManifest(),
|
||||
compiler.turnLaneArrows.loadManifest(),
|
||||
'the bundled turn-lane manifest is reused between compiles',
|
||||
);
|
||||
assert.equal(typeof compiler.complexJunction.buildComplexJunctionGeometry, 'function');
|
||||
assert.equal(typeof compiler.complexJunction.classifyJunctionShape, 'function');
|
||||
assert.equal(typeof compiler.junctionStructure.buildJunctionStructure, 'function');
|
||||
|
||||
Reference in new issue
Block a user