angular-drag-and-drop-lists icon indicating copy to clipboard operation
angular-drag-and-drop-lists copied to clipboard

Performance issue in the dragover event of the dndLists directive.

Open johntdowney opened this issue 8 years ago • 9 comments

Hey, just leaving this here for the author and/or those who care because I spent a little while solving this issue while working with a very large drag and drop list.

Line 339/340 is as follows:

listNode.insertBefore(placeholderNode,
	isFirstHalf ? listItemNode : listItemNode.nextSibling);

Replacing these two lines with

if(isFirstHalf) {
	if(listItemNode.previousSibling != placeholderNode) listNode.insertBefore(placeholderNode, listItemNode);
} else {
	if(listItemNode.nextSibling != placeholderNode) listNode.insertBefore(placeholderNode, listItemNode.nextSibling);
}

dramatically cuts down on the number of DOM layouts and improves the execution time of the dragover event handler. Without this, it's pretty hobbled at around ~60 dnd list items.

Thanks, John Downey

johntdowney avatar May 09 '17 20:05 johntdowney

amazing job @johntdowney I had a short list to work with, but with complex moving item. Replacing those lines did the magic. Thanks

tagisen avatar May 16 '17 12:05 tagisen

Awesome Job! Can Someone add it into the original source?

GeorgeChackungal avatar May 19 '17 17:05 GeorgeChackungal

Glad I could help! I see this "Close and comment" button, but I'm not sure of the etiquette here regarding whether or not I should close this issue since I opened it, so I'll just hit the comment button instead and assume someone with more authority can close it once the change has been applied.

johntdowney avatar May 20 '17 18:05 johntdowney

@marceljuenemann please review the PR, and run the minifier.

orlandovallejos avatar May 25 '17 22:05 orlandovallejos

Awesome! Thank you so much, that improve a lot than the original.

sinzii avatar Mar 25 '18 07:03 sinzii

Fantastic, thanks @johntdowney ! Has a PR been submitted for this fix?

abtx avatar Aug 08 '18 12:08 abtx

Thank you so much! Now the drag procedure is much, much more smoothly, especially on a Mac PC with Chrome.

I would like this library to be updated more constantly, the last update is from 2017!

sagg629 avatar May 17 '19 16:05 sagg629

You can improve performance a bit more by throttling:

      var throttle = true; 
      element.on('dragover', function(event) {
        if (throttle) {
          throttle = false;
          event = event.originalEvent || event;
          ...
          ent.addClass("dndDragover");
          event.stopPropagation();
          setTimeout(() => {
            throttle = true;
          }, 50);
        }
        return false;
      });

Miki-AG avatar Mar 18 '21 15:03 Miki-AG

I also added some throttling, using lodash. replacing line 310

element.on('dragover', function(event) {

with

element.on('dragover', _.throttle(dragOver, 50, { leading: true, trailing: false }))
function dragOver(event){

you'll also need to get rid of the extra bracket etc. at the end of the function

royalone avatar Jun 10 '22 02:06 royalone