Ah ok, I see now that you are looping over realizations. My previous comment does not hold. I can see only one potential inefficiency. It could be possible to have multiple realizations that have the same GSIM. For instance consider the case of a source model with 2 tectonic regions (A and B), and the GMPE logic tree defines only one GMPE for region A and two GMPEs for region B. If you do logic tree enumeration, you will have two realizations where sources belonging to region A are always associated to the same GMPE, so you will compute the same context objects twice. Would it possible to cache the context objects?