perf(editor): avoid unnecessary Set allocations in notVisibleShapes#7837
perf(editor): avoid unnecessary Set allocations in notVisibleShapes#7837steveruizok merged 1 commit intoperformance-stack-1from
Conversation
Optimize the notVisibleShapes derivation to reduce GC pressure: - Add fast path when all shapes are visible (return cached empty set) - On first run, compute from scratch - On subsequent runs, check if result differs before creating new Set - Only allocate new Set when contents actually changed Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| return emptySet | ||
| } | ||
| return prevValue | ||
| } |
There was a problem hiding this comment.
Shared empty set can be corrupted
Medium Severity
The fast path returns a shared mutable emptySet. Because getNotVisibleShapes() is public and returns the same Set instance, any external mutation of that set can persist across recomputations and cause incorrect culling results later (including after toggling between empty/non-empty states).
| return emptySet | ||
| } | ||
| return prevValue | ||
| } |
There was a problem hiding this comment.
All-visible shortcut relies on size equality
Low Severity
The “all shapes visible” fast path uses visibleIds.size === allShapeIds.size as a proxy for set equality. If getShapeIdsInsideBounds ever returns ids outside allShapeIds (e.g., stale spatial index), this can return an empty result even when some current-page shapes are outside the viewport.


Summary
This reduces GC pressure by avoiding unnecessary Set allocations on every frame.
Test plan
🤖 Generated with Claude Code
Note
Low Risk
Low risk performance refactor limited to
notVisibleShapesderivation; main risk is subtle cache/identity behavior affecting downstream consumers if the computed value no longer updates when expected.Overview
Optimizes
notVisibleShapesto reduce GC pressure by reusing Set instances instead of allocating a newSetevery recompute.Adds a fast path that returns a cached empty
Setwhen all shapes are visible, computes from scratch on the first run, and on subsequent runs scans to detect changes before building a newSet(returningprevValuewhen contents are unchanged).Written by Cursor Bugbot for commit e74207f. This will update automatically on new commits. Configure here.