-
Notifications
You must be signed in to change notification settings - Fork 558
perf(modeling): Expensive string key generation for Map lookups in scissionGeom3.js #1426
Copy link
Copy link
Open
Description
Summary
scissionGeom3.js converts vec3 arrays to strings for use as Map keys, which is expensive when done repeatedly.
Usage Frequency: LOW
Only used by scission() operation.
Typical model usage: Rare - maybe 1% of models
Problem
File: packages/modeling/src/operations/booleans/scissionGeom3.js
Lines: 9-22, 35
const insertMapping = (map, point, index) => {
const key = \`\${point}\` // Calls toString on array, creates string
const mapping = map.get(key)
if (mapping === undefined) {
map.set(key, [index])
} else {
mapping.push(index)
}
}
const findMapping = (map, point) => {
const key = \`\${point}\` // String creation again
return map.get(key)
}Called in loops:
polygons.forEach((polygon, index) => {
polygon.vertices.forEach((point) => {
insertMapping(indexesPerPoint, vec3.snap(temp, point, eps), index)
})
})For a geometry with 10,000 vertices, this creates 10,000+ strings just for lookups.
Suggested Fix
Consider alternative approaches:
- Use a spatial hash with integer keys
- Cache the string representation on first computation
- Use a custom Map implementation that handles vec3 keys directly
// Option 1: Spatial hash with integer key
const spatialKey = (point, eps) => {
const scale = 1 / eps
return \`\${Math.round(point[0] * scale)},\${Math.round(point[1] * scale)},\${Math.round(point[2] * scale)}\`
}
// This still creates strings but they're shorter and computed once per lookupImpact
Low overall (rare operation), but contributes to overhead when scission is used.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels