I was doing some work improving the performance of the reports.  Actually, I 
have 3 reports for which the performance has substantially improved, one of 
them is attached (cash flow).  The other, I'd rather clean up some more 
because it bypasses some of the normal report functions and I'd like to look 
into it more in depth.

Attached patch should improve the cash flow report by a factor of 7 or so (19 
sec to 2-3 sec for me).

Anyways, while I was doing some research on what people working on the SQL 
backend were saying, here's what I saw:
http://www.mail-archive.com/gnucash-devel%40gnucash.org/msg21775.html

When I read that, I realized I had fixed that, and decided I should include 
the part that takes care of that in this patch.  This part of the patch 
doesn't really improve report performance, but it does eliminate double 
query.  I have a more exhaustive patch to the net worth barchart (the 
income/expenses chart report is affected by that) that improves performance 
from 8 sec to almost instantly.  But that is the part I'd like to clean up 
some more first.

This patch is svn diff against the trunk.

-Tim
P.S. I'm not currently subscribed to this list
Index: src/report/standard-reports/net-barchart.scm
===================================================================
--- src/report/standard-reports/net-barchart.scm	(revision 17783)
+++ src/report/standard-reports/net-barchart.scm	(working copy)
@@ -262,14 +262,14 @@
        (set! assets-list
              (process-datelist
               (if inc-exp? 
-                  accounts
+                  (assoc-ref classified-accounts ACCT-TYPE-INCOME)
                   (assoc-ref classified-accounts ACCT-TYPE-ASSET))
               dates-list #t))
        (gnc:report-percent-done 70)
        (set! liability-list
              (process-datelist
               (if inc-exp?
-                  accounts
+                  (assoc-ref classified-accounts ACCT-TYPE-EXPENSE)
                   (assoc-ref classified-accounts ACCT-TYPE-LIABILITY))
               dates-list #f))
        (gnc:report-percent-done 80)
Index: src/report/standard-reports/cash-flow.scm
===================================================================
--- src/report/standard-reports/cash-flow.scm	(revision 17783)
+++ src/report/standard-reports/cash-flow.scm	(working copy)
@@ -152,23 +152,28 @@
     (define (same-account? a1 a2)
       (string=? (gncAccountGetGUID a1) (gncAccountGetGUID a2)))
 
-    (define (same-split? s1 s2) 
-      (string=? (gncSplitGetGUID s1) (gncSplitGetGUID s2)))
+    (define accounts-hashed
+     (let ((accounts-hashed (make-hash-table 100)))
+      (for-each
+       (lambda (account)
+        (hash-set! accounts-hashed (gncAccountGetGUID account) #t))
+       accounts)
+      accounts-hashed))
 
-    (define account-in-list?
-      (lambda (account accounts)
-        (cond
-          ((null? accounts) #f)
-          ((same-account? (car accounts) account) #t)
-          (else (account-in-list? account (cdr accounts))))))
+    (define seen-splits-map (make-hash-table 100))
+    
+    (define account-in-accounts-list?
+     (lambda (account)
+      (hash-ref accounts-hashed (gncAccountGetGUID account))))
 
-    (define split-in-list? 
-      (lambda (split splits)
-	(cond 
-	 ((null? splits) #f)
-	 ((same-split? (car splits) split) #t)
-	 (else (split-in-list? split (cdr splits))))))
+    (define split-seen?
+     (lambda (split)
+      (hash-ref seen-splits-map (gncSplitGetGUID split))))
 
+    (define add-split-seen
+     (lambda (split)
+      (hash-set! seen-splits-map (gncSplitGetGUID split) #t)))
+
     (define account-in-alist
       (lambda (account alist)
         (cond
@@ -204,7 +209,7 @@
         (let ((sub-accounts (gnc:acccounts-get-all-subaccounts accounts)))
           (for-each
             (lambda (sub-account)
-              (if (not (account-in-list? sub-account accounts))
+              (if (not (account-in-accounts-list? sub-account))
                   (set! accounts (append accounts sub-accounts))))
             sub-accounts)))
 
@@ -278,10 +283,10 @@
                                   ;(gnc:debug (xaccAccountGetName s-account))
                                   (if (and	 ;; make sure we don't have
 				       (not (null? s-account)) ;;  any dangling splits
-				       (not (account-in-list? s-account accounts)))
-				      (if (not (split-in-list? s seen-split-list))
+				       (not (account-in-accounts-list? s-account)))
+				      (if (not (split-seen? s))
 					  (begin  
-					    (set! seen-split-list (cons s seen-split-list))
+					    (add-split-seen s) 
 					    (if (gnc-numeric-negative-p s-value)
 						(let ((pair (account-in-alist s-account money-in-alist)))
 						  ;(gnc:debug "in:" (gnc-commodity-get-printname s-commodity)
@@ -304,6 +309,7 @@
 						    (money-in-collector 'add report-currency s-report-value)
 						    (s-account-in-collector 'add report-currency s-report-value))
 						  )
+						; Else s-value positive
 						(let ((pair (account-in-alist s-account money-out-alist)))
 						  ;(gnc:debug "out:" (gnc-commodity-get-printname s-commodity)
 						;	     (gnc-numeric-to-double s-amount)
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to