On save/submit of either Journal Entry, or Payment Entry, a query is run which sums up balance of the account and party. This query reads each and every entry belonging to account, something which is expected to increase with time, hence will cause JV and PE creation to slow down, with time (Imagine billions of transactions as seen with zerodha).
There seem to be 3 solutions (IMHO).
- Calculate balance in GL Entry after each transaction (non-scalable approach, transactions won’t be able to run concurrently, as they’ll be forced to run serially)
- Maintain a bin-like doctype for Account Balance (Again, every transaction will have to lock this document to update it, hence same problem as above)
- Remove balance calculation from PE and JV.
I support 3rd as balance is not really needed from PE. Any cancellation of previous PE will not update all future PEs, hence it’s only an indicative number, not actual. And, there is always awesome report called “General Ledger” if someone wants to view balance. That way, this costly calculation be only be done on demand, not always. And we can always optimise the ways to view balance in future in that report itself.