django-nested-admin icon indicating copy to clipboard operation
django-nested-admin copied to clipboard

Deleting child with lots of fields causes 10+ seconds of lag

Open emdemir opened this issue 6 years ago • 3 comments

I believe the culprit here is https://github.com/theatlantic/django-nested-admin/blob/de440b1333eeb9bd85ca412d717d0e89652207e7/nested_admin/static/nested_admin/src/nested-admin/jquery.djangoformset.js#L137 as it is referenced a lot when I profile the performance. https://stackoverflow.com/a/9180541 suggests that doing .html('') before the .remove() will increase performance dramatically. Haven't tested this, but will do once I have time.

emdemir avatar Jul 20 '19 18:07 emdemir

Did some minified file editing. Turns out jQuery is extremely slow for anything related to clearing out the inline form. The following gives the same amount of lag:

$form.html(""); // no change
self.remove($form);

The following, however, works:

$form[0].innerHTML = ""; // native DOM is superfast
self.remove($form);

Will send in a PR soon.

emdemir avatar Jul 20 '19 19:07 emdemir

To be on the safe side, if you're going to change that, it ought to be in the DjangoFormset .remove() method itself, before this line: https://github.com/theatlantic/django-nested-admin/blob/de440b1333eeb9bd85ca412d717d0e89652207e7/nested_admin/static/nested_admin/src/nested-admin/jquery.djangoformset.js#L166

fdintino avatar Jul 21 '19 01:07 fdintino

Will do.

emdemir avatar Jul 21 '19 07:07 emdemir