perf($q): reduce memory footprint

Reduce the memory footprint of $q by using common functions
that will be used by all promises.