Merge pull request #1 from LeieSistal/claude/incomplete-description-011CUoYUhUKUQqnPxEWrdbTB

perf: implement Phase 1 performance optimizations for large maps
This commit is contained in:
Leie Sistal 2025-11-04 23:02:41 +01:00 committed by GitHub
commit 160c37ce50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 403 additions and 12 deletions

View file

@ -1559,21 +1559,30 @@ function drawRivers() {
const {addMeandering, getRiverPath} = Rivers;
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
const riverPaths = pack.rivers.map(({cells, points, i, widthFactor, sourceWidth}) => {
if (!cells || cells.length < 2) return;
// PERFORMANCE OPTIMIZATION: Filter invalid rivers before processing
const validRivers = pack.rivers.filter(r => r.cells && r.cells.length >= 2);
// PERFORMANCE OPTIMIZATION: Pre-allocate array with exact size
const riverPaths = new Array(validRivers.length);
for (let idx = 0; idx < validRivers.length; idx++) {
const {cells, points, i, widthFactor, sourceWidth} = validRivers[idx];
let riverPoints = points;
if (points && points.length !== cells.length) {
console.error(
`River ${i} has ${cells.length} cells, but only ${points.length} points defined. Resetting points data`
);
points = undefined;
riverPoints = undefined;
}
const meanderedPoints = addMeandering(cells, points);
const meanderedPoints = addMeandering(cells, riverPoints);
const path = getRiverPath(meanderedPoints, widthFactor, sourceWidth);
return `<path id="river${i}" d="${path}"/>`;
});
rivers.html(riverPaths.join(""));
riverPaths[idx] = `<path id="river${i}" d="${path}"/>`;
}
// PERFORMANCE: Use single innerHTML write
rivers.node().innerHTML = riverPaths.join("");
TIME && console.timeEnd("drawRivers");
}