Optimize dragging performance with requestAnimationFrame#6541
Optimize dragging performance with requestAnimationFrame#6541walterbender merged 4 commits intosugarlabs:masterfrom
Conversation
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
1 similar comment
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
|
❌ Some Jest tests failed. Please check the logs and fix the issues before merging. Failed Tests: |
|
@walterbender , @Ashutoshx7 pls review this . Whenever free :) . Checking the jest test case |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@zealot-zew take a look update : i did test it out and did the code review looks goood to me |
|
@Sidharthwin thanks for working on this the raf throttle pattern is consistent with our current implementation in widgetwindows resizeRafId = requestAnimationFrame(() => {
if (!isResizing || !resizeDirection) {
resizeRafId = null;
return;
}
// ... rest of resize logic
}); |
|
Hey @Sidharthwin Using requestAnimationFrame here is absolutely the right call for improving dragging and resizing performance—nice work overall, the code looks really solid. There’s just one subtle issue with how the coordinates are being captured during the throttling. Right now, clientX and clientY are taken at the moment requestAnimationFrame is triggered, and any subsequent mousemove events get ignored until that frame finishes. Because of this, the UI ends up using the first coordinates within that ~16ms frame instead of the latest ones. The result is a slight lag where the dragged element doesn’t fully keep up with the cursor, especially noticeable when the mouse stops moving. Suggested fix: Could you apply this small adjustment in mb-dialog.js and also in both resize handlers within jseditor.js? |
hy i don't think so current implmentation is already good enough |
|
Hey @Ashutoshx7, you won't notice it on a fast laptop, but on lower-end devices it causes jitter. The current logic ignores the newest mouse movements during frame drops. It's only a 2-line change to make it completely bulletproof for all devices, let's just get it right!" |
but still i think having this as a addition is great ( just acts as a fallback or gaurdrail) |
Ashutoshx7
left a comment
There was a problem hiding this comment.
@zealot-zew whenever u get time take a look
i am approving look good to me
|
@Ashutoshx7 and @karthik-dev56 , Thanks for the feedback and suggestions . I will look into both the things , and get back to you with the best possible outcome |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@Ashutoshx7 and @karthik-dev56 , I agree with both of your feedbacks I've updated the implementation :
This should improve smoothness and avoid stale coordinate issues, especially on lower-end devices. |
|
@walterbender please you also give it a look , and tell me if any change is required |
|
@walterbender ready for the merge |
Summary
This PR improves performance when resizing dialogs (e.g., JS Editor and resizable widgets) by throttling
mousemove-based resize logic usingrequestAnimationFrame.Currently, resize logic is executed directly inside a
mousemoveevent handler, which can trigger hundreds of DOM updates per second. This leads to unnecessary layout recalculations and increased CPU usage during drag operations.Changes
Wrapped
doResizelogic inside arequestAnimationFrameloopEnsured only one resize update runs per frame
Reduced excessive DOM writes during continuous mouse movement
Applied changes to:
js/widgets/jseditor.jsjs/utils/mb-dialog.jsBefore
mousemoveeventAfter
Implementation Details
A simple RAF-based throttle was introduced:
requestAnimationFrameThis approach is consistent with existing optimizations used for block dragging.
Notes
This change focuses on improving performance without altering existing behavior or UI logic.
Checklist