-
Notifications
You must be signed in to change notification settings - Fork 27.5k
perf(orderBy): filters needlessly executed on every digest #16348
Comments
You are right that The suggestion you make is to compare the inputs, i.e. While in some cases, it might be true that doing this comparison upfront is faster, I believe that there are other scenarios where this would be slower: Since the output of the Given that the input If you know that the |
It'd be enough to watch only |
Also, I hardly agree with the "frequency: low" label. Everyone uses |
In five years you are the first to mention this :-) It can't be killing performance on that many applications. Of course any optimisation is worth it if it works. |
I wonder if there is something using interceptors that would work here?? |
Filters/interceptors only have the input-watching advantages when the inputs are also non-stateful which we (unfortunately) can't assume for anything other then primitive objects. Sometimes object/array literals will only have non-primitive inputs but that would probably be an edge case for any use of Filters/interceptors for arrays is where input-watching has always fallen short, and it has always bugged me. 97b00ca solved it for a few specific cases ( |
@thorn0 one other idea we thought of is the use of You could implement For |
Looks like what I was suggesting won't work for |
Individual situations can be easily solved like Pete described. But is there a chance to improve the performance of |
@thorn0 Do you have a suggestion for how we would implement that? |
No, unfortunately. That's what I'm asking. Is there infrastructure in place for doing something like this? Without deep diving into code I can't tell the answer from what @jbedard wrote, It seems to be no, but I thought I'd confirm. |
There is no infrastructure for doing this. It would require some "refactoring" :-) |
I've also just found (somewhat belatedly) that I'm suffering from this too. My application gets frequent updates over a WebSocket (sometimes as often as every 0.1s) which some pages need to listen to. The WebSocket is part of a Service which uses |
@raybellis - I am sorry about this. We are now in LTS so this behaviour is not going to change. You could try limiting the impact by throttling the calls to |
Throttling the I'm now working around it by using a separate member of |
p.s. the only reason this wasn't visible before was because I was using built-in sort predicates. It was only observed when I tried to implement a bespoke comparator function and then noticed how often that comparator was being called. |
I'm submitting a ...
Current behavior:
from the docs:
This effectively means that in all the instances of
ng-repeat
that useorderBy
, this filter is rerun on every digest. Instead of "costly" tracking the input array for changes, the framework first sorts this array and then still tracks it. The sorting part here is a pure performance loss which doesn't make any sense.Expected / new behavior:
Similar to the
$stateful
flag, it'd be great to have another flag for filters likeorderBy
. This flag will make the filter be executed only if its inputs have changed even if the inputs are objects.Minimal reproduction of the problem with instructions:
http://jsbin.com/nulonon/edit?html,js,output
AngularJS version: 1.6.x, 1.5.x
Browser: all
The text was updated successfully, but these errors were encountered: