Functions should be concise and self-explanatory. Any functions which look too large, or perform nested loops or recursion should be revisited. More computation means more gas, meaning it costs more to perform those functions.
Consider off-chain computing to take some load off your blockchain application. For example, decentralised exchanges use off-chain order filling algorithms to fill orders, since the algorithm is quite complex. Once an order is filled, the settlement is performed on the blockchain.
If reducing complexity is too difficult, consider the possibility that blockchain may not be the ideal solution to your problem.