You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bolt: Optimize layer visibility and opacity lookups
Replaces O(N * D) nested array lookups in sketch document layer traversals with O(D) operations by pre-computing a Map of layers and passing it to helpers like `isLayerCompositeVisible` and `getAncestorGroupOpacityProduct`.
Co-authored-by: georgi <19498+georgi@users.noreply.github.com>
**Learning:** Found multiple $O(N \times C)$ performance bottlenecks in `packages/data-nodes/src/nodes/data.ts` where `[...new Set(rows.flatMap(r => Object.keys(r)))]` was used to collect all unique column names across rows. This creates a massive intermediate array per row, flattens them, and passes the entire giant array to `Set`, causing extreme GC pressure and slow execution times. Additionally, in `DescribeNode`, a chained `.map().filter().every()` call created redundant array allocations.
75
75
**Action:** Replaced the `flatMap` pattern with a custom `getAllKeys(rows)` helper that iterates via standard `for...in` and populates a single `Set` directly. Also replaced the `DescribeNode` chain with a simple `for` loop that allows short-circuiting (`break`). These changes reduced processing time by over 4.5x and eliminated thousands of temporary array allocations.
76
+
## 2024-05-25 - O(N * M) Parent Lookups in Layer Tree Traversal
77
+
**Learning:** Functions like `isLayerCompositeVisible` and `getLayerDepth` were using `layers.find()` in `while` loops to traverse a layer's parent hierarchy. This caused an $O(N \times D)$ bottleneck (where D is depth) during operations that process all layers, significantly slowing down renders in sketches with many layers.
78
+
**Action:** Added an optional `layerMap` parameter to tree traversal helper functions. By pre-computing a `Map<string, Layer>` once and passing it down, the complexity was reduced to $O(D)$ per layer, dropping execution times by orders of magnitude for large documents.
0 commit comments