fix(sockets movement): smoother throttling + fix re-render bug#541
fix(sockets movement): smoother throttling + fix re-render bug#541waleedlatif1 merged 2 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
✅ No security or compliance issues detected. Reviewed everything up to 81cbdd8. Security Overview
Detected Code Changes
Reply to this PR with |
There was a problem hiding this comment.
PR Summary
Implements performance optimizations for collaborative workflow editing with improved socket movement handling and throttling mechanisms.
- Increased socket throttling from 60fps to 120fps (16ms to 8ms) in
apps/sim/contexts/socket-context.tsxfor smoother real-time updates - Replaced interval-based throttling with optimized timeout-based approach in socket context to reduce memory overhead
- Added explicit store version of updateBlockPosition in
apps/sim/app/w/[id]/workflow.tsxto prevent collaborative editing feedback loops - Implemented collaborative position updates during node dragging for better multi-user synchronization
- Fixed workflow switching state management to properly handle variable states
2 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile
| // Check if we already have a pending timeout for this block | ||
| if (!positionUpdateTimeouts.current.has(blockId)) { | ||
| // Schedule emission with light throttling (120fps = ~8ms) | ||
| const timeoutId = window.setTimeout(() => { | ||
| const latestUpdate = pendingPositionUpdates.current.get(blockId) | ||
| if (latestUpdate) { | ||
| socket.emit('workflow-operation', latestUpdate) | ||
| pendingPositionUpdates.current.delete(blockId) | ||
| } else { | ||
| // No more updates pending - stop the interval | ||
| clearInterval(intervalId) | ||
| positionUpdateTimeouts.current.delete(blockId) | ||
| } | ||
| }, THROTTLE_DELAY) | ||
|
|
||
| positionUpdateTimeouts.current.set(blockId, intervalId) | ||
| positionUpdateTimeouts.current.delete(blockId) | ||
| }, 8) // 120fps for smooth movement | ||
|
|
||
| // Set a cleanup timeout to stop the interval if no updates come in | ||
| setTimeout(() => { | ||
| if (positionUpdateTimeouts.current.get(blockId) === intervalId) { | ||
| clearInterval(intervalId) | ||
| positionUpdateTimeouts.current.delete(blockId) | ||
| pendingPositionUpdates.current.delete(blockId) | ||
| } | ||
| }, 50) // Stop interval after 50ms of no updates | ||
| positionUpdateTimeouts.current.set(blockId, timeoutId) | ||
| } |
There was a problem hiding this comment.
style: Consider using requestAnimationFrame instead of setTimeout for better performance and synchronization with browser render cycles
| // Very light throttling at 120fps (8ms) to prevent excessive spam | ||
| if (now - lastCursorEmit.current >= 8) { | ||
| socket.emit('cursor-update', { cursor }) | ||
| lastCursorEmit.current = now | ||
| } |
There was a problem hiding this comment.
style: Use a config constant for the throttle delay (8ms) to maintain consistency with other timing values
* fix(sockets movement): smoother throttling strategy and re-render bug fix * works --------- Co-authored-by: Vikhyath Mondreti <vikhyathmondreti@Vikhyaths-Air.attlocal.net>
Description
Throttling set to 120 FPS. And use collaborative update only on user actions.
Fixes # (issue)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Checklist:
bun run test)Security Considerations:
Additional Information:
Any additional information, configuration or data that might be necessary to reproduce the issue or use the feature.