I have a function in my contract loops through the current user base (an address[]), within each loop, it performs some logic and writes some data into state user variables.
The function starts to fail when the user base gets larger then 30 due to gas cost exceed block gas limit.
I wonder if this is a good solution here -
I can offload the loops to front end js, just call the function to write results onchain after each loop, in this way although I need to make more calls to write data onchain, at least each call will not exceed block gas limit. Then it is more scalable.
Is this a good way for gas optimization?