ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.04k stars 1.2k forks source link

Slow collection of widgets on big grids #451

Open hwanders opened 9 years ago

hwanders commented 9 years ago

I found iterations over potentially large structures + collections which indeed got slow for me. They use $.each with $.proxy-fied callbacks and were collecting widget elements by calling $xxx = $xxx.add(...) here:

fn.get_widgets_under_player fn.get_widgets_overlapped fn.widgets_below

This became noticable when having small widget_base_dimensions with wide widgets at the top; it took a long time until dragging such a widget actually started. I could reduce the delay very much by using primitive iteration over the according arrays / array-like objects combined with traditional collection in a native array and checking for duplicate elements using indexOf there. Transformation to a jQuery set can be done at the end with $mySet = $(mySetOfJQobjectsAsArray).map(function() { return this.toArray(); });