emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Henahan <jhenahan@me.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] `org-clock--oldest-date` performance
Date: Sat, 20 Jan 2018 16:06:29 -0500	[thread overview]
Message-ID: <m1wp0c9r56.fsf@me.com> (raw)
In-Reply-To: <m18tcsb7a3.fsf@me.com>

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

I've sent off for the FSF form so I can get that process started, and
I've amended my patch according to the guidelines (attached).

Jack Henahan <jhenahan@me.com> writes:

> I tested that `org-clock-display` and the clocktable work as expected
> when `org-clock-display-default-range` is set to `untilnow`.
> `org-clock-sum-custom` also appears to function as intended. If I'm
> reading things correctly, the `untilnow` case is the only one that ought
> to be affected, since it's the only one that used
> `org-clock--oldest-date`. The behavior of `org-clock-special-range`
> ought to be unchanged in all cases except where this symbol is
> explicitly used, or the start time is nil for some other reason.
>
> Functionally, this means that today `org-clock-special-range` produces a
> range from the current time until the current time if `start` ends up
> nil for whatever reason, but with this patch it will instead produce a
> range from the year -50000 until now. The -50000 hack is entirely for
> the benefit of `format-time-string`, since otherwise it just gives the
> current time if its second argument is nil.
>
>> Jack Henahan <jhenahan@me.com> writes:
>>
>>> Apologies again, didn't update the commit hash properly. I swear this is
>>> the last one. :|
>>
>> Thank you. However, I'm surprised that `org-clock-special-range' callers
>> handle a nil start date. Have you tested it?
>>
>> If that's true, we don't need the -50000 hack at all. Returning an empty
>> string might be enough.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-clock.el-Improve-untilnow-range-behavior-and-per.patch --]
[-- Type: text/x-patch, Size: 3388 bytes --]

From a4add4ef44c4f445b4c029a0f0a7ef6f3d5d606b Mon Sep 17 00:00:00 2001
From: Jack Henahan <jhenahan@me.com>
Date: Sat, 20 Jan 2018 12:07:11 -0500
Subject: [PATCH] org-clock.el: Improve `untilnow' range behavior and
 performance

* org-clock.el:
(org-clock-special-range): Set `untilnow' to use the year -50000,
rather than the earliest representable date.
(org-clock--oldest-date): Remove.

The `untilnow' range relied on the constant `org-clock--oldest-date`
to find the earliest representable date, which caused delays when
loading `org-clock' on systems where `most-negative-fixnum' is large.
This change removes that constant in favor of a simpler hack to
produce a range between the current time and before the dawn of human
civilization. If this breaks your workflow, please report to the Time
Police.
---
 lisp/org-clock.el | 42 +++++++-----------------------------------
 1 file changed, 7 insertions(+), 35 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 496c4310a..519b1563b 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -468,38 +468,6 @@ to add an effort property.")
 (defvar org-clock-stored-resume-clock nil
   "Clock to resume, saved by `org-clock-load'")
 
-(defconst org-clock--oldest-date
-  (let* ((dichotomy
-	  (lambda (min max pred)
-	    (if (funcall pred min) min
-	      (cl-incf min)
-	      (while (> (- max min) 1)
-		(let ((mean (+ (ash min -1) (ash max -1) (logand min max 1))))
-		  (if (funcall pred mean) (setq max mean) (setq min mean)))))
-	    max))
-	 (high
-	  (funcall dichotomy
-		   most-negative-fixnum
-		   0
-		   (lambda (m)
-                     ;; libc in macOS 10.6 hangs when decoding times
-                     ;; around year -2**31.  Limit `high' not to go
-                     ;; any earlier than that.
-                     (unless (and (eq system-type 'darwin)
-                                  (string-match-p
-                                   "10\\.6\\.[[:digit:]]"
-                                   (shell-command-to-string
-                                    "sw_vers -productVersion"))
-                                  (<= m -1034058203135))
-                       (ignore-errors (decode-time (list m 0)))))))
-	 (low
-	  (funcall dichotomy
-		   most-negative-fixnum
-		   0
-		   (lambda (m) (ignore-errors (decode-time (list high m)))))))
-    (list high low))
-  "Internal time for oldest date representable on the system.")
-
 ;;; The clock for measuring work time.
 
 (defvar org-mode-line-string "")
@@ -2260,7 +2228,7 @@ have priority."
     ;; Format start and end times according to AS-STRINGS.
     (let* ((start (pcase key
 		    (`interactive (org-read-date nil t nil "Range start? "))
-		    (`untilnow org-clock--oldest-date)
+		    (`untilnow nil)
 		    (_ (encode-time 0 m h d month y))))
 	   (end (pcase key
 		  (`interactive (org-read-date nil t nil "Range end? "))
@@ -2283,8 +2251,12 @@ have priority."
 	      (`interactive "(Range interactively set)")
 	      (`untilnow "now"))))
       (if (not as-strings) (list start end text)
-	(let ((f (cdr org-time-stamp-formats)))
-	  (list (format-time-string f start)
+	(let ((f (cdr org-time-stamp-formats))
+              (safe-start
+	       (if (not start)
+		   (encode-time 0 0 0 0 0 -50000)
+		 start)))
+	  (list (format-time-string f safe-start)
 		(format-time-string f end)
 		text))))))
 
-- 
2.15.1


  reply	other threads:[~2018-01-20 21:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-20  6:52 `org-clock--oldest-date` performance Jack Henahan
2018-01-20 11:14 ` Nicolas Goaziou
2018-01-20 17:00   ` [PATCH] " Jack Henahan
2018-01-20 17:05     ` Jack Henahan
2018-01-20 17:09       ` Jack Henahan
2018-01-20 18:18         ` Nicolas Goaziou
2018-01-20 20:32           ` Jack Henahan
2018-01-20 21:06             ` Jack Henahan [this message]
2018-01-21  9:42             ` Nicolas Goaziou
2018-01-21 16:04               ` Jack Henahan
2018-01-21 22:30                 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1wp0c9r56.fsf@me.com \
    --to=jhenahan@me.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).