canvasObjectsUnderCollection recomputes on every prefab instance regenerate #37

Open
opened 2026-08-19 15:23:25 +00:00 by ImBenji · 0 comments
Owner

MapDataProvider.canvasObjectsUnderCollection sweeps _collectionParentOf to a fixpoint and then filters every canvas object by _imageParentOf, so it costs roughly O(collections × sweeps + canvasObjects) per call.

regeneratePrefabInstance calls it once per instance, and regenerateAllInstancesOfPrefab calls that once per instance of the prefab. So editing a prefab's master, or attaching a script to it, walks the whole collection tree and the whole canvas-object list once for every live instance.

Irrelevant at current scale — a handful of prefabs and a few dozen canvas objects. Filing it because it's the first place to look if stamped prefabs get used heavily on a large map. A spider map with a stamped panel per stop is the shape that would hit it hardest, since that's many instances of one prefab all regenerating together.

Cheapest fix is probably memoising the descendant set per master collection and invalidating on hierarchy change, rather than making the sweep itself cleverer. Introduced alongside the stamp path in #35.

`MapDataProvider.canvasObjectsUnderCollection` sweeps `_collectionParentOf` to a fixpoint and then filters every canvas object by `_imageParentOf`, so it costs roughly O(collections × sweeps + canvasObjects) per call. `regeneratePrefabInstance` calls it once per instance, and `regenerateAllInstancesOfPrefab` calls that once per instance of the prefab. So editing a prefab's master, or attaching a script to it, walks the whole collection tree and the whole canvas-object list once for every live instance. Irrelevant at current scale — a handful of prefabs and a few dozen canvas objects. Filing it because it's the first place to look if stamped prefabs get used heavily on a large map. A spider map with a stamped panel per stop is the shape that would hit it hardest, since that's many instances of one prefab all regenerating together. Cheapest fix is probably memoising the descendant set per master collection and invalidating on hierarchy change, rather than making the sweep itself cleverer. Introduced alongside the stamp path in #35.
ImBenji added the enhancementarea:performance labels 2026-08-19 15:23:25 +00:00
ImBenji added this to the Arcs & Angles project 2026-08-19 15:23:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: IMBENJI.NET/Metro-Map-Maker#37