Some small performance optimisations.

Most significant is the replacement of `Maybe (Either Resource
Resource)` with `Box` to distinguish with a STM transaction if a
resource has been created new, was used before or is absent.