MessagesManagerImpl uses UserManager.getAllUsers() to retrieve all users on then filters for the ones having a certain group assigned. This can become very slow in case there's lots of users in the system. See linked issues for similar cases.
Caution: be careful to consider transitive groups as well when e.g. replacing with calls to UserManager's new methods introduced by