In case you do not have it like this yet, I would have an idea for an optimization.
Do not calculate the resource production often. Calculate it when a production-influencing value changes and save the result.
Then only work with the result instead of calculating it anew every time.
Only update the result when a production-influencing value changes.
Production-influencing values are:
Building levels (build/destroy) of res prod
Researches (for example vespene research of xerjs)
Alliance taxes
Dominance taxes
OPS appears/disappears
Dues (taken capital key)
A couple of Medals
Planet colonization (important for imperium view's total)
A couple of officers/mutants/elders
Amortization
Depletion
I think you get what I mean with it. Only when one of this values changes re-calculate the stored results. If the implementation of this is possible it should significantly reduce the necessary calculations.
Just an idea..
Addition: I was bored and made you a drawing..
http://prntscr.com/ofkyq6