Performance fixes to EntityManager.