From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id EKO7DuVJ92LnIwEAbAwnHQ (envelope-from ) for ; Sat, 13 Aug 2022 08:51:17 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id aGPlDeVJ92LYpgAAG6o9tA (envelope-from ) for ; Sat, 13 Aug 2022 08:51:17 +0200 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 DDDC837204 for ; Sat, 13 Aug 2022 08:51:16 +0200 (CEST) Received: from localhost ([::1]:39714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMkzM-0002Hc-24 for larch@yhetil.org; Sat, 13 Aug 2022 02:51:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMkxh-0002HN-B5 for emacs-orgmode@gnu.org; Sat, 13 Aug 2022 02:49:34 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:36741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMkxf-0005Lp-EX for emacs-orgmode@gnu.org; Sat, 13 Aug 2022 02:49:32 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 15-20020a17090a098f00b001f305b453feso10137614pjo.1 for ; Fri, 12 Aug 2022 23:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc; bh=Avmg/IHmYmdPtuA/VdJXvWURGzO0/ccvRzE8TaefFRs=; b=mLwIYXUc5EFuIj4RqgtU+HygUJAusMn4nMmk81Lbbdih2mHS01A6Ei7JwpYiR+Frk2 klA1JSFAk8Ho+gnUy29qT1Ld9pnyl2ibETsSAAsgKdizaZ/CDLqT98dDuAhr/Gj9kKhm tlGesj9yeNgNV7Xgtq0QRp5QDdQOy1RmRiS/6L1TK1aojndTin0MmsmsW9/V3PPdFoXX j+1S4JNriKNUnovL7b4g4Ft8X+tUrvY2qyyC/DYw8Sepoc/UHowhWQhtfuHpj1IlyRFP aTY5TTslOrNj9RES9o0Ge1CKL53MHXoBMGJTa3wS8YOZU7p1nVNWPL2CncvB2HyfmfIN 0KOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc; bh=Avmg/IHmYmdPtuA/VdJXvWURGzO0/ccvRzE8TaefFRs=; b=VuKBZazbeskcipdY0PBM/gKrUUeQ++IFpqzwxqs/LIG7JMiXslEYezjPUNySNUDaK6 E8dOfNaSYBxYBhdreyuw+6THTsnOtVSk24s7mrCBjfCMk5MgZ9E6wIu7pDitfYtiANNI b/SNA1GpNwncUDV9y0qWMblF3tTxnPh8R72pLmXObAx7fYGJw/7br2DUocxUIJc18ZYv aK826MgWvB2edfGEPz7aDdkqmIXoA+JkKbPAjN7+keXzPWRRMDJj5dURH2WXGFuIYuJU V5RVHKnEP7k292dJgPIhMiCgkE9YtZG4eIbeXJ2ZTVSCoyrZ/rg39puvUXyiCXjC0oyP fu9A== X-Gm-Message-State: ACgBeo01c+jygx/bT2B6c4Ilf8ItDhAJZ4uD33wCMDexE2HxL51hPG5J aIsEKTexynQoATRsMQ6QILk= X-Google-Smtp-Source: AA6agR7tfzZIjmma5HYN8nXbYre/0AVWxTd173gL6NbCpj5SR0yhA3lq/I+n6LZ406adI56NKUE0Xw== X-Received: by 2002:a17:90a:9ce:b0:1f3:c90:6e99 with SMTP id 72-20020a17090a09ce00b001f30c906e99mr17605117pjo.211.1660373369752; Fri, 12 Aug 2022 23:49:29 -0700 (PDT) Received: from localhost ([2409:8a70:2bf:80b0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id z14-20020aa7990e000000b0052b29fd7982sm2732616pff.85.2022.08.12.23.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 23:49:28 -0700 (PDT) From: Ihor Radchenko To: "Christopher M. Miles" Cc: Org Mode Subject: Re: [PERFORMANCE] Why some org code is so deep invoked? In-Reply-To: <62f66552.050a0220.ed346.ac05SMTPIN_ADDED_BROKEN@mx.google.com> References: <62f5a905.c80a0220.1f07b.ffaeSMTPIN_ADDED_BROKEN@mx.google.com> <87o7wq8c1m.fsf@localhost> <62f645de.050a0220.ff872.76ffSMTPIN_ADDED_BROKEN@mx.google.com> <87h72h8v1j.fsf@localhost> <62f66552.050a0220.ed346.ac05SMTPIN_ADDED_BROKEN@mx.google.com> Date: Sat, 13 Aug 2022 14:50:30 +0800 Message-ID: <87lers7i2x.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=yantar92@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1660373476; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Avmg/IHmYmdPtuA/VdJXvWURGzO0/ccvRzE8TaefFRs=; b=DJ8JD6xxf0PLIZ/JYFWJA0dTNRZqbOBl15zte4KcfMF0hLC94u5jEv1gIGvSDg8EdXZNlI WOQLPEDTa6kkKVxr4XLHB/6ZRum20ANahI3bRckMWO6TEr5US97dtooz3/tEy9TGMAVRHS XSUlqsQcxhtqqpDRr9iaOreB30OHdyMgG9hUvtkNpZRjok9TU+k2EvK/vlaEEpbPJ76ps/ UKkSd9p/7774svxFmdy1EA96mP5Sufr2bbHn+G3ngOVwaXO9G6k5Z8eY9DOdwB+jew8+M9 uyKLm+EH4IJmSEmG1Miv8XhOl1awc4nc1DYR+bkhnb5sctDQS0BrebschtKp5g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1660373476; a=rsa-sha256; cv=none; b=Uc9qegFFwJUPr3BoLrRHOm7gepa4hMCr+6jhiv/tBYszFICH71fq7gKpFT5bRtU8so5+RY OOCpOa/DH9GzSGYHDon5gpe1yp3vpgBli9a/OiGmolDgLQmfqzfctIFGKdB5gkeVTVI1vt 3C/RXYH9Sy9Z/0058qohQTGMIWjnBd6gfjUlYi+3sVSfuBcNXsCn3RMFLTq4Nrvixsfhcs SNhPeaPu3fiUfBjNSZxnXuZicrePXxGw9w0t8PfNILxAoJCfER1djOUBnZApXheb487mKi lOWrAr5Lb6GO0eLTRFC7T5c6ceKhnPs/9D+2641y4p4W796+O54JFQpRh8e8Jw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mLwIYXUc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -0.86 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mLwIYXUc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: DDDC837204 X-Spam-Score: -0.86 X-Migadu-Scanner: scn1.migadu.com X-TUID: ceHCsPKAxnpd --=-=-= Content-Type: text/plain "Christopher M. Miles" writes: > 668 28% - org-agenda-prepare-buffers > ... > 523 22% - org--tag-add-to-alist I have a suspicion where the bottleneck is. Can you try the attached patch? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-agenda-prepare-buffers-Avoid-quadratic-behavior-.patch >From 1f5cdbd05c7012962ba3f12671805d77f52d836e Mon Sep 17 00:00:00 2001 Message-Id: <1f5cdbd05c7012962ba3f12671805d77f52d836e.1660373309.git.yantar92@gmail.com> From: Ihor Radchenko Date: Sat, 13 Aug 2022 14:45:01 +0800 Subject: [PATCH] org-agenda-prepare-buffers: Avoid quadratic behavior when merging tags * lisp/org.el (org-agenda-prepare-buffers): Use the shortest list as the first argument in `org--tag-add-to-alist'. `org--tag-add-to-alist' is looping over the first argument. When we use the accumulated tags as the first argument, each buffer tag will need to be looped over N_buffers/2 times on average, creating quadratic complexity. Avoid this. Reported in https://orgmode.org/list/62f66552.050a0220.ed346.ac05SMTPIN_ADDED_BROKEN@mx.google.com --- lisp/org.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 4eef56f45..b21bdf291 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15196,8 +15196,8 @@ (defun org-agenda-prepare-buffers (files) (append org-todo-keyword-alist-for-agenda org-todo-key-alist)) (setq org-tag-alist-for-agenda (org--tag-add-to-alist - org-tag-alist-for-agenda - org-current-tag-alist)) + org-current-tag-alist + org-tag-alist-for-agenda)) ;; Merge current file's tag groups into global ;; `org-tag-groups-alist-for-agenda'. (when org-group-tags -- 2.35.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 --=-=-=--