From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH] Optimize org-habit-parse-todo Date: Tue, 25 Jan 2011 07:01:54 +0100 Message-ID: References: <87mxmxys27.fsf@fastmail.fm> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=57696 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Phbyb-0000oB-0J for emacs-orgmode@gnu.org; Tue, 25 Jan 2011 01:02:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhbyX-0001xK-8K for emacs-orgmode@gnu.org; Tue, 25 Jan 2011 01:02:01 -0500 Received: from mail-ew0-f41.google.com ([209.85.215.41]:50545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhbyX-0001xA-3t for emacs-orgmode@gnu.org; Tue, 25 Jan 2011 01:01:57 -0500 Received: by ewy27 with SMTP id 27so2280276ewy.0 for ; Mon, 24 Jan 2011 22:01:56 -0800 (PST) In-Reply-To: <87mxmxys27.fsf@fastmail.fm> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Org Mode Hi Matt Hmmm, this looks like a very important optimisation indeed. I am just wondering if it is always safe to do it like this. Have you checked if this is influenced by org-reverse-notes-order or similar things? - Carsten On Jan 19, 2011, at 1:39 PM, Matt Lundin wrote: > * lisp/org-habit.el: (org-habit-parse-todo) Don't parse more days than > needed. > > When constructing a consistency graph, org-habit (with this patch) > will > stop searching for timestamps when the number of matches exceeds the > span of time displayed in the graph. This can produce a significant > speedup in agenda construction, especially for entries with many > logbook > entries. Previously, org-habit would parse all logbook timestamps, > even > if they numbered in the hundreds. > > Before: > org-habit-parse-todo 33 0.7357430000 0.0222952424 > After: > org-habit-parse-todo 33 0.11648 0.0035296969 > > This patch respects the value of org-log-states-order-reversed, but > assumes that users do not frequently change its value (and thus the > order of their log entries). > --- > lisp/org-habit.el | 16 ++++++++++++---- > 1 files changed, 12 insertions(+), 4 deletions(-) > > diff --git a/lisp/org-habit.el b/lisp/org-habit.el > index b174a1f..a05dd1b 100644 > --- a/lisp/org-habit.el > +++ b/lisp/org-habit.el > @@ -170,10 +170,18 @@ This list represents a \"habit\" for the rest > of this module." > habit-entry scheduled-repeat)) > (setq deadline (+ scheduled (- dr-days sr-days)))) > (org-back-to-heading t) > - (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\ > \]" end t) > - (push (time-to-days > - (org-time-string-to-time (match-string-no-properties 1))) > - closed-dates)) > + (let* ((maxdays (+ org-habit-preceding-days org-habit- > following-days)) > + (reversed org-log-states-order-reversed) > + (search (if reversed 're-search-forward 're-search-backward)) > + (limit (if reversed end (point))) > + (count 0)) > + (unless reversed (goto-char end)) > + (while (and (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" > limit t) > + (< count maxdays)) > + (push (time-to-days > + (org-time-string-to-time (match-string-no-properties 1))) > + closed-dates) > + (setq count (1+ count)))) > (list scheduled sr-days deadline dr-days closed-dates)))) > > (defsubst org-habit-scheduled (habit) > -- > 1.7.3.5 > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode