open-admin icon indicating copy to clipboard operation
open-admin copied to clipboard

Optimization in select_all function to reduce browser freeze

Open haboshi opened this issue 1 year ago • 1 comments

Optimization in select_all function to reduce browser freeze

Problem Description

When using the select_all function within the framework, there is a significant performance issue leading to browser freezing. This seems to be due to the fact that the function currently triggers a click event for each row, causing excessive resource consumption, especially when there are many rows.

https://github.com/open-admin-org/open-admin/blob/8e39330b8f3f3994e36ca2045a7ec56c8075d28f/resources/assets/open-admin/js/open-admin-grid.js#L44

Steps to Reproduce

  1. Navigate to [specific page or feature where issue occurs].
  2. Try to select all rows using the select_all feature.
  3. Notice that with a high number of rows, the browser becomes unresponsive.

Proposed Solution

Instead of triggering a click event for each row, I suggest changing the method to directly update the checked property of each checkbox. This reduces the unnecessary overhead of repeatedly triggering events.

Original Code:

box.click();

Optimized Code:

box.checked = checkbox.checked;

Original Code:

  • Significant performance improvement, especially with a large number of rows.
  • Reduces the likelihood of the browser becoming unresponsive.

haboshi avatar Aug 22 '23 11:08 haboshi

@haboshi thanks for the tip! The reason for the click, was because it should invert the selection. I was not aware of the ^= operator yet. now using: box.checked ^= checkbox.checked;

Fixed in dev-branch, will release soon.

open-admin-org avatar Nov 08 '23 21:11 open-admin-org