Skip to content

perf(editor): replace lodash isEqual with optimized Set comparisons#7839

Merged
steveruizok merged 1 commit intoperformance-stack-1from
sr/perf-isEqual-sets
Feb 4, 2026
Merged

perf(editor): replace lodash isEqual with optimized Set comparisons#7839
steveruizok merged 1 commit intoperformance-stack-1from
sr/perf-isEqual-sets

Conversation

@steveruizok
Copy link
Copy Markdown
Collaborator

@steveruizok steveruizok commented Feb 4, 2026

In order to fix a major performance bottleneck in large multiplayer rooms, this PR replaces expensive lodash deep equality checks with custom equality functions optimized for Sets.

lodash's isEqual doesn't handle Sets efficiently - it likely converts them to arrays for deep comparison. With thousands of shapes in large multiplayer rooms, this was causing significant performance overhead on every frame during the equality checks in computed signals.

Change type

  • improvement

Test plan

  1. Open a large multiplayer room with many shapes
  2. Check flame graph - isEqual should no longer appear in hot paths
  • Unit tests
  • End to end tests

Release notes

  • Improve performance in large multiplayer rooms by replacing lodash deep equality with optimized Set comparisons

Replace expensive lodash deep equality checks with custom equality functions
optimized for Sets and structured data:

- Add setsEqual() that uses Set.has() for O(n) comparison instead of lodash's
  inefficient Set handling
- Add arraysEqual() for reference equality array comparison
- Add renderDataEqual() for structured comparison of indicator render data
- Remove lodash isEqual imports from CanvasShapeIndicators and usePeerIds

This fixes a major performance bottleneck in large multiplayer rooms where
lodash's isEqual was doing expensive deep comparisons on Sets with thousands
of shape IDs on every frame.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Feb 4, 2026 5:41pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Feb 4, 2026 5:41pm
chat-template Ignored Ignored Preview Feb 4, 2026 5:41pm
tldraw-docs Ignored Ignored Feb 4, 2026 5:41pm
tldraw-shader Ignored Ignored Feb 4, 2026 5:41pm
workflow-template Ignored Ignored Feb 4, 2026 5:41pm

Request Review

@steveruizok steveruizok added the improvement Product improvement label Feb 4, 2026
@steveruizok steveruizok changed the base branch from main to performance-stack-1 February 4, 2026 17:50
@steveruizok steveruizok merged commit 0d0ec46 into performance-stack-1 Feb 4, 2026
20 checks passed
@steveruizok steveruizok deleted the sr/perf-isEqual-sets branch February 4, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Product improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant