From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Henahan Subject: Re: [PATCH] `org-clock--oldest-date` performance Date: Sat, 20 Jan 2018 12:09:45 -0500 Message-ID: References: <87po64ok7n.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecweQ-0006IY-Mq for emacs-orgmode@gnu.org; Sat, 20 Jan 2018 12:09:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecweM-00070w-F6 for emacs-orgmode@gnu.org; Sat, 20 Jan 2018 12:09:54 -0500 Received: from ms11p00im-qufv17100601.me.com ([17.58.37.33]:26188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ecweM-000709-7R for emacs-orgmode@gnu.org; Sat, 20 Jan 2018 12:09:50 -0500 Received: from process-dkim-sign-daemon.ms11p00im-qufv17100601.me.com by ms11p00im-qufv17100601.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P2V00E0067UMZ00@ms11p00im-qufv17100601.me.com> for emacs-orgmode@gnu.org; Sat, 20 Jan 2018 17:09:49 +0000 (GMT) Received: from icloud.com ([127.0.0.1]) by ms11p00im-qufv17100601.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P2V00MWJ6C9DJ20@ms11p00im-qufv17100601.me.com> for emacs-orgmode@gnu.org; Sat, 20 Jan 2018 17:09:49 +0000 (GMT) In-reply-to: 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 Jack Henahan writes: Apologies again, didn't update the commit hash properly. I swear this is the last one. :| > Jack Henahan writes: > > Modified patch attached to use my list mail rather than my work one. > >> To that end, I've attached a patch for review which removes >> `org-clock--oldest-date`, replacing its only use with `nil`, and >> altering the logic where it's actually used to account for this case and >> give a sensible-ish value of the year -50000 for the start time in >> `org-special-range`. Before the dawn of humanity seemed like a >> reasonable limit, but I'm taking suggestions. :D >> >> I'm not certain if this hits the "modify 15 lines" threshold since it's >> mainly deletion, but I'll start getting the paperwork in order and write >> a Changelog entry. >> >> Nicolas Goaziou writes: >> >>> Hello, >>> >>> Jack Henahan writes: >>> >>>> I've run into a performance issue in `org-clock` which I've narrowed >>>> down to being caused by the calculation in the defconst for >>>> `org-clock--oldest-date`. In particular, invoking `org-clock-in` or >>>> eagerly loading `org-clock` on init incurs a 21(!) second delay while >>>> calculating the constant. If I inline the value (`(-1034058236842 >>>> -45726)`, in my case), the delay vanishes. >>>> >>>> So, context out of the way (just in case someone else already knows an >>>> easier fix), I'd like to spend some spare cycles finding a better way to >>>> go about the functionality this is meant to provide. If I've read the >>>> source correctly, it's meant to provide a view of all the clocks by >>>> showing all clocks between some time way in the past until now. >>> >>> A correct fix would be to remove `org-clock--oldest-date', which is used >>> only in one place, and replace it with nil. Then all >>> `org-clock-special-range' callers need to be updated to handle this nil >>> start value. >>> >>> Regards, --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Set-untilnow-to-use-the-year-50000-rather-than-the-e.patch >From 29969da1e47032f0b3691ba1dd14bd836488990d Mon Sep 17 00:00:00 2001 From: Jack Henahan Date: Sat, 20 Jan 2018 12:07:11 -0500 Subject: [PATCH] Set `untilnow` to use the year -50000, rather than the earliest representable date. --- 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 --=-=-=--