emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Optimize org-habit-parse-todo
@ 2011-01-19 12:39 Matt Lundin
  2011-01-25  6:01 ` Carsten Dominik
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Lundin @ 2011-01-19 12:39 UTC (permalink / raw)
  To: Org Mode

* 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Optimize org-habit-parse-todo
  2011-01-19 12:39 [PATCH] Optimize org-habit-parse-todo Matt Lundin
@ 2011-01-25  6:01 ` Carsten Dominik
  2011-01-25  6:21   ` Carsten Dominik
  0 siblings, 1 reply; 6+ messages in thread
From: Carsten Dominik @ 2011-01-25  6:01 UTC (permalink / raw)
  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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Optimize org-habit-parse-todo
  2011-01-25  6:01 ` Carsten Dominik
@ 2011-01-25  6:21   ` Carsten Dominik
  2011-01-25 20:03     ` Matt Lundin
  0 siblings, 1 reply; 6+ messages in thread
From: Carsten Dominik @ 2011-01-25  6:21 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Matt Lundin, Org Mode


On Jan 25, 2011, at 7:01 AM, Carsten Dominik wrote:

> 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?

I am sorry, I see now that this is done correctly.
One request, can you resubmit and test for the count
first, before doing the search?  Just another very
minor optimization.


- Carsten

>
> - 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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Optimize org-habit-parse-todo
  2011-01-25  6:21   ` Carsten Dominik
@ 2011-01-25 20:03     ` Matt Lundin
  2011-01-25 21:59       ` [Accepted] " Carsten Dominik
  2011-01-25 21:59       ` [PATCH] " Carsten Dominik
  0 siblings, 2 replies; 6+ messages in thread
From: Matt Lundin @ 2011-01-25 20:03 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode

* lisp/org-habit.el: (org-habit-parse-todo) Don't parse more days than
  needed.

When constructing a consistency graph, org-habit now stops searching
for timestamps when the number of matches exceeds the span of time
displayed in the graph. This can lead to 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.
---
 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..5d2514a 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 (< count maxdays)
+		    (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" limit t))
+	  (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

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On Jan 25, 2011, at 7:01 AM, Carsten Dominik wrote:
>
>> 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?
>
> I am sorry, I see now that this is done correctly.
> One request, can you resubmit and test for the count
> first, before doing the search?  Just another very
> minor optimization.

Thanks Carsten!

See the updated patch above. The next step is to make the keyword search
configurable....

Best,
Matt

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Accepted] Optimize org-habit-parse-todo
  2011-01-25 20:03     ` Matt Lundin
@ 2011-01-25 21:59       ` Carsten Dominik
  2011-01-25 21:59       ` [PATCH] " Carsten Dominik
  1 sibling, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2011-01-25 21:59 UTC (permalink / raw)
  To: emacs-orgmode

Patch 558 (http://patchwork.newartisans.com/patch/558/) is now "Accepted".

Maintainer comment: No comment

This relates to the following submission:

http://mid.gmane.org/%3C87sjwgn42k.fsf%40fastmail.fm%3E

Here is the original message containing the patch:

> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode] Optimize org-habit-parse-todo
> Date: Wed, 26 Jan 2011 01:03:47 -0000
> From: Matt Lundin <mdl@imapmail.org>
> X-Patchwork-Id: 558
> Message-Id: <87sjwgn42k.fsf@fastmail.fm>
> To: Carsten Dominik <carsten.dominik@gmail.com>
> Cc: Org Mode <emacs-orgmode@gnu.org>
> 
> * lisp/org-habit.el: (org-habit-parse-todo) Don't parse more days than
>   needed.
> 
> When constructing a consistency graph, org-habit now stops searching
> for timestamps when the number of matches exceeds the span of time
> displayed in the graph. This can lead to 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.
> 
> ---
> 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..5d2514a 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 (< count maxdays)
> +		    (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" limit t))
> +	  (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)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Optimize org-habit-parse-todo
  2011-01-25 20:03     ` Matt Lundin
  2011-01-25 21:59       ` [Accepted] " Carsten Dominik
@ 2011-01-25 21:59       ` Carsten Dominik
  1 sibling, 0 replies; 6+ messages in thread
From: Carsten Dominik @ 2011-01-25 21:59 UTC (permalink / raw)
  To: Matt Lundin; +Cc: Org Mode

Applied, thanks.

- Carsten

On Jan 25, 2011, at 9:03 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 now stops searching
> for timestamps when the number of matches exceeds the span of time
> displayed in the graph. This can lead to 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.
> ---
> 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..5d2514a 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 (< count maxdays)
> +		    (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" limit t))
> +	  (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
>
> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> On Jan 25, 2011, at 7:01 AM, Carsten Dominik wrote:
>>
>>> 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?
>>
>> I am sorry, I see now that this is done correctly.
>> One request, can you resubmit and test for the count
>> first, before doing the search?  Just another very
>> minor optimization.
>
> Thanks Carsten!
>
> See the updated patch above. The next step is to make the keyword  
> search
> configurable....
>
> Best,
> Matt
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-01-29 22:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-19 12:39 [PATCH] Optimize org-habit-parse-todo Matt Lundin
2011-01-25  6:01 ` Carsten Dominik
2011-01-25  6:21   ` Carsten Dominik
2011-01-25 20:03     ` Matt Lundin
2011-01-25 21:59       ` [Accepted] " Carsten Dominik
2011-01-25 21:59       ` [PATCH] " Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).