From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GOEwA6E5jGDzGwEAgWs5BA (envelope-from ) for ; Fri, 30 Apr 2021 19:08:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id ODRyOqA5jGArYgAAbx9fmQ (envelope-from ) for ; Fri, 30 Apr 2021 17:08:48 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 70492222EC for ; Fri, 30 Apr 2021 19:08:48 +0200 (CEST) Received: from localhost ([::1]:38208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcWdD-0005jb-Jx for larch@yhetil.org; Fri, 30 Apr 2021 13:08:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcWRV-0003rn-Db for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 12:56:42 -0400 Received: from ciao.gmane.io ([116.202.254.214]:50014) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcWRT-0001sL-45 for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 12:56:40 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lcWRN-0005l6-9i for emacs-orgmode@gnu.org; Fri, 30 Apr 2021 18:56:33 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: Re: [PATCH] Bug: fragile org refile cache Date: Fri, 30 Apr 2021 23:56:27 +0700 Message-ID: References: <87v98598un.fsf@localhost> <87k0olxjpz.fsf@localhost> <877dklxecq.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 In-Reply-To: <877dklxecq.fsf@localhost> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619802528; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=K8jyMLd2alJ9gOQuMSQAhMk7dvrqocFNZ32akh9AAg8=; b=Z5htjKwBQgCJq5KqirovMPESIfieBW54QXkfvlNZnZWrq6WYQIar2lrqrg8eISsp9GjtAF KUL/eqUcQn7zqNASEoG8acW4hCPdzgdB1rZ/Kzho6JkuSxEYZV4EGAZqmlDUiaHiMDXqXu 73e6FNUa1TbTW4EHZg900s9UOu16I2vis2sRCZi008TRL8exLOFK5MvCATNavJU8oG7B2Z hNsU6JFNLojGTYrQgojE/jU7EbNT5tVZLh9pUS1pfHW6rz8uInjD3OBtZrlJpUo7p9yspc +cJ8aGdWVeos16nuFl1PdQLUyX9JwxPNyzrz+v1zwSQuQFDwApSBquLONjba0A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619802528; a=rsa-sha256; cv=none; b=D6gHbKgUXKRJdHTSv+fK+aF5uJyklyQNCXjJk3bx2z1EiRTKu/1wEA37ogRFOx1xFizWf4 zzP6yIVdz+5xplho3sSHWb9DJsBuCWgzPen4ZFcN4NzNPIwqID9z43Y5JSwQ13WZl5qyXE cDuqig+Rp+lpXUqLxy/tqrl8OGJpPEY4RnD3nmZjbXkzeH1wejetOyldBVO2ZLdgt1ptI1 UEzTqN/MTPHBPq0yzLWMG3h1UJiP8IaEvjHlTwDRKyhcE64rvZ52B0oK+1ufKslW1pzXFf C+3VIxSjAuOOR8b9295vLTMO4GpKn5S8BAVOYqKaKsek0GUMEfwGfOSpfRSPNg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.86 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 70492222EC X-Spam-Score: -1.86 X-Migadu-Scanner: scn0.migadu.com X-TUID: D9i/87OT2Ggh On 29/04/2021 23:08, Ihor Radchenko wrote: > Did you do any benchmarks? I just tried > > Outline path without cache: I have expanded your tests to make them more close to org-get-outline-path org-get-outline-path without cache | 5.459114059 | 12 | 1.2053580009999987 | org-get-outline-path with cache | 2.166378543 | 5 | 0.5011187770000003 | Custom code to track outline path during scan | 0.718288205 | 4 | 0.4005034349999992 | The same without (org-trim ...) stuff | 0.208798040 | 0 | 0.0 | From my point of view avoiding org-get-outline-path allows to significantly improve performance. Removing cookies, etc. is far from being negligible. Test file is org-manual.org with 404 headings. Since it is not so much, I set minimal CPU frequency. Notice that outline cache is cleared before each scan to simulate the case when org-goto is invoked just after emacs start or after adding/removing some lines in the beginning of the file. Actually it is a problem of outline cache that it easily became stale due to e.g. extra line close to buffer start. Details: #+begin_example bash for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo powersave >"$i" ; done #+end_example #+begin_src elisp (byte-compile-file (expand-file-name "~/src/emacs/org-mode/lisp/org.el")) (defun nm-count-headings (headings) (let ((n 0)) (dolist (h headings) (setq n (+ n (length h)))) (list (length headings) n))) #+end_src #+RESULTS: : nm-count-headings #+begin_src elisp (defun ir-tst-scan (buffer use-cache) (with-current-buffer buffer (goto-char 1) (let ((result nil)) (while (re-search-forward "^\\*+[ \t]" nil t) (beginning-of-line) (let ((case-fold-search nil)) (looking-at org-complex-heading-regexp)) (push (org-get-outline-path t use-cache) result) (end-of-line)) result))) (byte-compile 'ir-tst-scan) (mapcar (lambda (use-cache) (let ((headings)) (append (list use-cache) (benchmark-run 10 (progn (setq org-outline-path-cache nil) (setq headings (ir-tst-scan "org-manual.org" use-cache)))) (nm-count-headings headings)))) '(nil t)) #+end_src #+RESULTS: | nil | 5.459114059 | 12 | 1.2053580009999987 | 404 | 1069 | | t | 2.166378543 | 5 | 0.5011187770000003 | 404 | 1069 | | use-cache | benchmark | | | headings | outline components | #+begin_src elisp (defun nm-tst-scan (buffer clean-headers) (with-current-buffer buffer (goto-char 1) (let ((result nil)) (let ((outline-path)) (while (re-search-forward "^\\*+[ \t]" nil t) (beginning-of-line) (let ((case-fold-search nil)) (looking-at org-complex-heading-regexp)) (let ((heading (match-string-no-properties 4)) (heading-level (length (match-string-no-properties 1)))) (while (and outline-path (<= heading-level (caar outline-path))) (pop outline-path)) (push (cons heading-level (if (not heading) "" (if (not clean-headers) heading (org-trim (org-link-display-format (replace-regexp-in-string "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" "" heading)))))) outline-path)) (end-of-line) (push (mapcar #'cdr outline-path) result))) result))) (byte-compile 'nm-tst-scan) (mapcar (lambda (clean-headers) (let ((headings)) (append (list clean-headers) (benchmark-run 10 (progn (setq org-outline-path-cache nil) (setq headings (nm-tst-scan "org-manual.org" clean-headers)))) (nm-count-headings headings)))) '(nil t)) #+end_src #+RESULTS: | nil | 0.20879804000000002 | 0 | 0.0 | 404 | 1069 | | t | 0.718288205 | 4 | 0.4005034349999992 | 404 | 1069 | | clean-headers | benchmark | | | headings | outline components |