perf(API): Tune middleware execution

Improve performance of interating through middleware components by
performing the getattr lookups ahead of time. Also push and pop from
the tail of the middleware stack, rather than the head, since that
is more efficient for the underlying list type.