gnucash maint: [balsheet-pnl] unrealized-gain calculator is now much faster.

Christopher Lam clam at code.gnucash.org
Tue Nov 26 09:03:27 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/1af8e272 (commit)
	from  https://github.com/Gnucash/gnucash/commit/ff298b36 (commit)



commit 1af8e272c7603cd08bad11a2f9374e234710783c
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Tue Nov 26 21:33:33 2019 +0800

    [balsheet-pnl] unrealized-gain calculator is now much faster.
    
    Previous code would call gnc:account-get-comm-value-at-date for each
    report-date; this function generates qof-query, retrieves account
    splits, scans them to accumulate split->transaction->currency and
    split->value into a commodity collector.
    
    This commit will hook into the existing gnc:account-accumulate
    function, accumulating the same split->transaction->currency and
    split->value into a collector.
    
    Note we must make a copy of the accumulator at each report-date
    via (gnc:collector+ val-coll) otherwise the same val-coll will be
    mutated through subsequent splits.
    
    For a multicolumn balsheet, for every account with N old splits, and
    reporting on M report dates, it would run in O(N*M) time. This
    algorithm will hook into existing accumulator, i.e. I think O(1).
    
    The majority speed-up however comes from avoiding M qof-queries per
    report.



Summary of changes:
 gnucash/report/standard-reports/balsheet-pnl.scm | 56 ++++++++++++++++++++----
 1 file changed, 48 insertions(+), 8 deletions(-)



More information about the gnucash-patches mailing list