$q is probably due for a rewrite #5223
Description
Given the importance of promises to the angularJS way, it is probably worth spending some time considering weaknesses in the $q models:
-
while compliant with much older versions of the promises-aplus spec, it is nowhere near complaint with the present 2.x spec and test suites. Since the 2.x suites are focused, in particular about integration of promises with foreign "thenable" libraries, this is actually pretty important.
-
$q promises are very heavyweight objects, taking more than 750 bytes of heap space per defer/promise pair. The main culprit here is that each promise contains a repeated and identical copy of all the functions used in the closure. This is one of the reason why most major promise implementations use prototypes in one way or the other to reduce the footprint. A flyweight version so implemented usually uses less than 10-50 bytes per instance.
-
There are a few features that are meaningful conveniences that require no space.
As understood, the primary motivations for the existing model is compactness and simplicity. I believe these features can be maintained while bringing $q up to date and flyweight, but it would require a major restructuring.
I'm inclined to volunteer for the project, but am curious if anybody else is looking at the issue, or wishes to chime in on requirements. Mine are:
-
identical API, perhaps with additional features (like a resolver instance for promise creation);
-
Flyweight implementation;
-
Conforms to most current promises-aplus specification (and hence far better integration with foreign thenables).