From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Henahan Subject: Re: [PATCH] `org-clock--oldest-date` performance Date: Sun, 21 Jan 2018 11:04:24 -0500 Message-ID: References: <87po64ok7n.fsf@nicolasgoaziou.fr> <87y3ksmm0m.fsf@nicolasgoaziou.fr> <87lggrmtuf.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edI6l-0006WN-Iq for emacs-orgmode@gnu.org; Sun, 21 Jan 2018 11:04:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edI6i-00079q-EP for emacs-orgmode@gnu.org; Sun, 21 Jan 2018 11:04:35 -0500 Received: from ms11p00im-qufv17110101.me.com ([17.58.37.18]:57205) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edI6i-00077r-71 for emacs-orgmode@gnu.org; Sun, 21 Jan 2018 11:04:32 -0500 Received: from process-dkim-sign-daemon.ms11p00im-qufv17110101.me.com by ms11p00im-qufv17110101.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P2W00400XYZWU00@ms11p00im-qufv17110101.me.com> for emacs-orgmode@gnu.org; Sun, 21 Jan 2018 16:04:28 +0000 (GMT) Received: from icloud.com ([127.0.0.1]) by ms11p00im-qufv17110101.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P2W00H3IXZC2G20@ms11p00im-qufv17110101.me.com> for emacs-orgmode@gnu.org; Sun, 21 Jan 2018 16:04:28 +0000 (GMT) In-reply-to: <87lggrmtuf.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain I wasn't altogether certain that it could never be nil, and my eyes seem to have skipped over the expression you called out so I missed that case in my testing. I have reworked the patch as you suggest. Now the behavior should be entirely unchanged except in the `untilnow' case where we use the new date, no extra nils. Revised patch attached. Nicolas Goaziou writes: > Hello, > > Jack Henahan writes: > >> 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 > > That's not true. Currently, `org-clock-special-range' never returns > a nil start time. This is where I don't understand your patch: > >> - (`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) > ^^^^^ > this can now be nil >> - (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)))))) > > Why not replacing `org-clock--oldest-date' with (encode-time > 0 0 0 0 0 -50000) in the let binding above? > > Regards, --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-clock.el-Improve-untilnow-range-behavior-and.patch >From a0792b3900812b6a2385794f30ba7c057bc9fcf7 Mon Sep 17 00:00:00 2001 From: Jack Henahan Date: Sun, 21 Jan 2018 10:40:22 -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 | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 496c4310a..d580ffa43 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,8 @@ 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) + ;; In theory, all clocks started after the dawn of humanity + (`untilnow (encode-time 0 0 0 0 0 -50000)) (_ (encode-time 0 m h d month y)))) (end (pcase key (`interactive (org-read-date nil t nil "Range end? ")) -- 2.15.1 --=-=-=--