-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$watch - group watcher callbacks that have the same watch expression and context #13731
Comments
This sounds like an interesting idea (not without some caveats though). Unfortunately, the Further more, there would be some watcher registration overhead (having to loop through all watchers and compare the expressions), especially on scopes with many watchers. The good thing is that there is no global "registry" of watchers, rather every scopemaintains its own list, so the watchers are already grouped per context (context --> scope). It would be definitely interesting if we could have some benchmarks with a prototype implementation and see if it's indeed an improvement. |
@gkalpak I might try to come up with some prototypical implementation in my spare time if this sounds like a valid idea. I was wondering if I am first one to come up with it or maybe it was discussed internally at some point. I cannot give eta on this but I'll try to make some time :) |
I'm not aware of any such discussion. Maybe @petebacondarwin or @lgalfaso now something more :) |
it is not the first time this idea came up. In fact, a similar idea is what triggered the Angular 2 watch tower implementation. At the time (this was some time ago, so the ideas/conclusions can be revisited) the ideas were that this should work automagically. This is, if the same expression is registered multiple times, then the expression would be evaluated less times. I am skipping many details as the conversation was extremely long and involved several design docs that are present in the Angular 2 design docs folder. At the time, the conversation revolved around performance and not making things easier for the developer, as it is strait-forward to implement the idea of one expression to multiple listeners if performance is not an issue. The conclusion was that, if performance was not an issue, then it was better not to add any extra complexity to the core. If performance is an issue, then to do it right, it would need some BC that would be better to avoid. |
@lgalfaso well the idea seems to be very simple so I was wondering what kept you from implementing it. I will check out the design docs and the Angular 2 watch tower you are referring to. I might try to implement a prototype anyway :) |
I was wondering if you guys ever considered grouping watchers that have same watch expression and context into one watcher with multiple concurrent callback. I have implemented it for angular-formly and I'm wondering if this was good idea and maybe I missed something.
Check the example below how I've done it manually. It could be probably implemented in the core in similar way. Of course there are some holes as it should know if the watcher is deep or shallow and I didn't implement unwatching of single watcher because I had no use case for that but it all could be managed.
The text was updated successfully, but these errors were encountered: