I see that you have a typo in your code
var myPG1= tw.system.org.findParticipantGroupByName("role1");
var allUsers = myPG1.allUsers;
for (var i=0; i<allUsers.length; i++)
try a refresh once and time the individual steps which one is taking long time findPG or .allUsers also time the refresh also, idea being you may need to call refresh only once and caching should happen after that, I remember we had a situation where calling the refresh on a scheduled basis though a timer UCA helped.