Improving performance on get_balance_on() function

Hi All,

I notice that this function get_balance_on() (in erpnext.account.utils) is called on multiple place in ERPNext, now, this function actually do a sum of debit - sum of credit, overtime, this is very heavy. I don’t think accounting period closing help. If I look at the code its not looking into period closing at all, but I may be mistaken… The thing is, when the number of records become huge, the DB is hammered pretty hard. This function is also called multiple times in many actions.

Is there any settings to prevent this function to scan the entire GL Entry table, instead, getting the last summarized total for records from different fiscal year?

Will greatly appreciate performance tips and tricks on this area.

Thanks a lot.