Getting a Confluence Userprofile is very slow


For a loop of over 4000 users the following code is not consistent in terms of performance.

for(String username:allUsers){
UserProfile userProfile = this.userManager.getUserProfile(username);

For Jira the same call is quick (around 1 sec) and for confluence it is taking around 10-12 mins
Why is there a substantial difference? Any pointers?
Let me know if you need any more details.