angular-multi-select icon indicating copy to clipboard operation
angular-multi-select copied to clipboard

Performance Bug : Digest on one instance triggers on digest on others

Open jsrkstr opened this issue 10 years ago • 8 comments

If have multiple multi selects in one page, on opening on multiselect, digest is run on every other instance. When I have 30+ multiselects, it takes 3 seconds to open a multiselect.

jsrkstr avatar Jul 24 '15 07:07 jsrkstr

Hi @jsrockstar132 ,

Noted, thanks for this. Will take note for future version.

isteven avatar Aug 17 '15 07:08 isteven

Hey isteven,

we´re facing the exact same problem here. We´re using a function to generate our inputmodels and have about 10 places where we use your directive. Everytime we open/hover/click any element in any directive, every instance of the directive updates their complete input model.

In real browsers the performance issue is notable but tolerable. In all versions of IE, the javacript engine however has serious issues computing all the method calls and freezes for up to 10 seconds.

jannisbreitwieser avatar Aug 20 '15 14:08 jannisbreitwieser

Hi @jannisbreitwieser ,

May I know if you re-use the same input-model $scope variable for every instance of the directive?

isteven avatar Aug 20 '15 15:08 isteven

Hi steven,

we´ve got one "view/template" that uses a single controller. This controller has a single $scope variable. On this $scope a function is defined like: $scope.calculateInputModel();

In the template the directive is used about 10 times like .

Hovering over an option for example causes the calculateInputModel() method to be called n (number of directive - 10 in this case) times.

Tested both with multi-select 2.x and the current 4.x version of the directive. Also had a look at your code. At first glance I dont understand, why the input-model is a two way binding here?

Hope that helps.

Jannis

jannisbreitwieser avatar Aug 21 '15 09:08 jannisbreitwieser

Hi,

Perhaps to make it clear; did you use the same input model for each directive? Say:

Controller

$scope.myArrOfObjects = [ ..... ]

View

Select 1
<div isteven-multi-select input-model="myArrOfObjects" .... ></div>
Select 2
<div isteven-multi-select input-model="myArrOfObjects" .... ></div>
Select 3
<div isteven-multi-select input-model="myArrOfObjects" .... ></div>

May I know if it's like that? Or perhaps you can replicate your code in Plunker or JsFIddler.

isteven avatar Aug 22 '15 09:08 isteven

The second watcher for scope.inputModel is causing problems in IE, Pages get stuck if you have multiple multi-select directives Disabled it temporarily at the cost of the reset button functionality.

// watch1, for changes in input model property
// updates multi-select when user select/deselect a single checkbox programatically
// https://github.com/isteven/angular-multi-select/issues/8
$scope.$watch( 'inputModel' , function( newVal ) {

    if ( newVal ) {
        $scope.refreshOutputModel();
        $scope.refreshButton();
    }
}, true );

 //watch2 for changes in input model as a whole
 //this on updates the multi-select when a user load a whole new input-model. We also update the $scope.backUp variable
$scope.$watch( 'inputModel' , function( newVal ) {

    if ( newVal ) {
        $scope.backUp = angular.copy( $scope.inputModel );
        $scope.updateFilter();
        $scope.prepareGrouping();
        $scope.prepareIndex();
        $scope.refreshOutputModel();
        $scope.refreshButton();
    }
});

valorbreak avatar Sep 24 '15 18:09 valorbreak

Use angular.copy(data) to make data different!!! If data in select boxes the same... to prevent it

jgluhov avatar Oct 09 '15 07:10 jgluhov

jqgrid multiselect disabling the whole thing takes a lot of time any suggestions on how to improve the disabling time.

k2kkapoor avatar Jul 21 '16 05:07 k2kkapoor