fredsa / gwt-dnd

Library providing easy to use mouse or touch based drag-and-drop capabilities to GWT
42 stars 41 forks source link

Performance problems when mousing over draggable items (with 1000's of draggables) #134

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Does the issue occur in "quirks mode", "standards mode" or both? If you
don't know, does your HTML page contains a DOCTYPE declaration?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

What version of GWT are you using? 1.4.60? 2.0.4? Other?
2.0.3

What version of the gwt-dnd jar file or library file are you using?
3.0.0

What operating system(s) are you using? Windows? Linux? Mac?
Window 7 64bit

Does the issue occur in web mode, development mode (formerly "hosted
mode"), both or don't know?
Web mode

What browser(s) do you use? Chrome, Firefox, IE, Safari, other?
Chrome

What is the browser version (if you know) from Help->About?
8.0.552.210 beta

What steps will reproduce the problem? Please attach sample code if you
can.
This was an issue that came up while I was profiling my application (Choosel) 
to improve the overall performance. I found that on Chrome 8, when mousing over 
items gwt-dnd used *a lot* of CPU time, although I did not drag anything. I had 
over 2000 draggable labels.

What is the expected output? What do you see instead?
The performance should not be affected that much when not dragging anything.

Do you have a workaround?
I looked at the code of MouseDragHandler (the profiling indicated that the 
performance penalties were caused by calculating the x,y coordinates of DOM 
elements). Often, those operations are unnecessary, so I moved some tests that 
existed in onMouseDown and onMouseMove to the beginning of those methods. The 
expensive DOM element location lookup now gets only executed when required, and 
this solved the performance problems. I attached a patch for MouseDragHandler 
revision 992 (3.0.0).

Original issue reported on code.google.com by Lars.Grammel on 4 Dec 2010 at 7:16

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the bug report, suggested fix and proposed patch. I've incorporated 
part of your suggested onMouseDown change in r1064.

I did not apply the proposed change to onMouseMove since this method is now 
only called during dragging. As of r1024, the MouseDragHandler only adds mouse 
down (and now,  touch start) handlers on your draggables or drag handlers. It 
does not add mouse move handlers to your draggables and drag handles.

You can see the that the extra onMouseMove events are no longer firing unless 
you are dragging in this demo:
http://allen-sauer.com/com.allen_sauer.gwt.dnd.demo.DragDropDemo/DragDropDemo.ht
ml#MatryoshkaExample

Original comment by fredsa@google.com on 17 Dec 2010 at 4:09