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 ms0.migadu.com with LMTPS id CJCaMVMeG2IN7wAAgWs5BA (envelope-from ) for ; Sun, 27 Feb 2022 07:46:43 +0100 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 SDFcKlMeG2I0fQEAG6o9tA (envelope-from ) for ; Sun, 27 Feb 2022 07:46:43 +0100 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 3DC9439BB3 for ; Sun, 27 Feb 2022 07:46:43 +0100 (CET) Received: from localhost ([::1]:56196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nODKL-0000zC-Lo for larch@yhetil.org; Sun, 27 Feb 2022 01:46:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nODHo-0000yc-Gq for emacs-orgmode@gnu.org; Sun, 27 Feb 2022 01:44:05 -0500 Received: from [2607:f8b0:4864:20::52c] (port=34626 helo=mail-pg1-x52c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nODHm-0007sM-18 for emacs-orgmode@gnu.org; Sun, 27 Feb 2022 01:44:03 -0500 Received: by mail-pg1-x52c.google.com with SMTP id 139so8701708pge.1 for ; Sat, 26 Feb 2022 22:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=wYljf4MER1xrCLUqjXm92Qdk9G6tid5MyY49xz60Grg=; b=fsszCcMVtnWDhFvVG8VJXIykyXxp9eVDYA8H+iDosp9KEaG7V6l1Z8v+ME8EiLgKMz kqsd0QMrXaBHpZ6qrS6rsBRSnay1uyK5NQpLd8bKqpYh5CQhSoim3hpkhDIrBXpSz7Lj ZKK1TBP5zuVo8dDem7tnhkAn+w2lQzuTzc/I1Qs45O0mTpIWbBQrKVmrDXt+pW4uvuKi 3xGnh0fj5nrxVlF8McTL0csBP7WBOAsab8b9O6O+l2Hvy4bf1ncpl0qS+tJrervNv7fr YxdlYVlWUV89T/iDBieyw94H2DoaeSBv+Wl3Rp7rOuarrzDhmRJjBzSJudSXpiqrqBlm XXow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=wYljf4MER1xrCLUqjXm92Qdk9G6tid5MyY49xz60Grg=; b=N7FeMYlubwg7Iv+oMcx/g9VkSJF5vWBSe2f+Q//aEBtus1xsMaVulvfcyM7BN1aDtl H/Sj3FuBoF32idDIRiAIvKFuD7/o/vycB1iIP13dC+rlS16BukJgdSVxiu4RhVO5J3NC JooWyDFEm03fDV1lVhENgplhmsQjRA/w8UTaEh1SUHX5US8Wi3D/e0maIvHGT2kjTH9e 9DkLsTvYYuisRjVJk4zCtDnCp9VRYwBMjZ8F+QgCvzII2v0NKkaR65QgqD2J9eWTqTMN Qu9Jyhm2jYAts3aX65kCKJoDYpaTtLYxmTqHI7806OSYzGje6STr8RwhAAxHd1cT2Aan rvoA== X-Gm-Message-State: AOAM533D1RuNYD4dRwj8kF+OGHloceY17X5v6/R51jHucWJXbVr75Nw3 MVDXwFC9jPb9nfvDjUsh1o4= X-Google-Smtp-Source: ABdhPJwzsVvRDqxhpe7vzEKhsFc73EytVcy7OQrPW+FxzVTjn7GLiakHfrbTBIfpGECzXT6/LJQIEw== X-Received: by 2002:a62:8895:0:b0:4e1:78b:5ab7 with SMTP id l143-20020a628895000000b004e1078b5ab7mr15847051pfd.67.1645944239317; Sat, 26 Feb 2022 22:43:59 -0800 (PST) Received: from localhost ([211.21.210.181]) by smtp.gmail.com with ESMTPSA id 8-20020a056a00070800b004e14ae3e8d7sm8651141pfl.164.2022.02.26.22.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 22:43:58 -0800 (PST) From: Ihor Radchenko To: Max Nikulin Subject: Re: profiling latency in large org-mode buffers (under both main & org-fold feature) In-Reply-To: References: <87fsobpism.fsf@localhost> <87r17to817.fsf@localhost> <87lexy2hrz.fsf@localhost> Date: Sun, 27 Feb 2022 14:43:29 +0800 Message-ID: <87y21wkdwu.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52c (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=yantar92@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: 11 X-Spam_score: 1.1 X-Spam_bar: + X-Spam_report: (1.1 / 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, FROM_FMBLA_NEWDOM=1.498, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645944403; 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=wYljf4MER1xrCLUqjXm92Qdk9G6tid5MyY49xz60Grg=; b=D7df2j222tj7r9sZdLNLf9vACGdc0ChIQmwr8I0CpsgpK5vqCz0xpUgYP2PhAgZuv37xqh AunGaj/SaaPuY+E/jm1SI78UmFuGydpdwHEBprd96SyvsBor4yiJAc762DTEMIxlv/dfMd teAzRfDUJutERwhpa8HcAVVA254fJErRPsRpvUBUK8j7e+Dz76j2Zw+Lwupnb9YvuY0+Aq UUmSYSQRS3bcMTbnHIjSBkX/HTaprO7B9q0XDXHFgVsUKsjElOtYzaxb9FBKqmb6dQLBEF yKtMV4TZC4tGLBbjnVUtH8nxnV30Ypyq7Sz+d4FUvKVkxP9HKwkXOV7ymdZ0SQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645944403; a=rsa-sha256; cv=none; b=bc2R4V1sIdgHg+T8dP2ovssoquMpHBa1Hy1fSQHafYfzj+nadDWhEYXyukUM36ypFWThnv 5cpzWcYU3EHng2oBEjbVmIgy7IttsdX4iGJzOm+kNjFZA4dnI4HsKKOxv6BqJcQzIeQnc7 uhaBs+YHX9L1+YaxE7G/fPeDLn/7Wg0rd0lpaOXholQdLDjshfp4WYtDe6cR9t9oJhgSt9 yHKPTA3p4oboEac89A9ZDSigvnO9CA/cTw25rWDN7rB8kSx6IpJpP7jWh6iEYv3TzSC3vy 0d9mUGEkNxJFEU9QHfqwIbny6gGHUP29yNOZzvRUrEJ72jvmWzN0DitsmlNVaQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fsszCcMV; 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: -3.81 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fsszCcMV; 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: 3DC9439BB3 X-Spam-Score: -3.81 X-Migadu-Scanner: scn0.migadu.com X-TUID: G9cmrwHlqeLL Max Nikulin writes: >> Max Nikulin writes: >>> Actually I suspect that markers may have a similar problem during regexp >>> searches. I am curious if it is possible to invoke a kind of "vacuum" >>> (in SQL parlance). Folding all headings and resetting refile cache does >>> not restore performance to the initial state at session startup. Maybe >>> it is effect of incremental searches. >> >> I doubt that markers have anything to do with regexp search itself >> (directly). They should only come into play when editing text in buffer, >> where their performance is also O(N_markers). > > I believed, your confirmed my conclusion earlier: > > Ihor Radchenko. Re: [BUG] org-goto slows down org-set-property. > Sun, 11 Jul 2021 19:49:08 +0800. > https://list.orgmode.org/orgmode/87lf6dul3f.fsf@localhost/ I confirmed that invoking org-refile-get-targets slows down your nm-tst looping over the headlines. However, the issue is not with outline-next-heading there. Profiling shows that the slowdown mostly happens in org-get-property-block I have looked into regexp search C source and I did not find anything that could depend on the number markers in buffer. After further analysis now (after your email), I found that I may be wrong and regexp search might actually be affected. Now, I did an extended profiling of what is happening using perf: ;; perf cpu with refile cache (using your previous code on my largest Org buffer) 19.68% [.] mark_object 6.20% [.] buf_bytepos_to_charpos 5.66% [.] re_match_2_internal 5.33% [.] exec_byte_code 5.07% [.] rpl_re_search_2 3.09% [.] Fmemq 2.56% [.] allocate_vectorlike 1.86% [.] sweep_vectors 1.47% [.] mark_objects 1.45% [.] pdumper_marked_p_impl ;; perf cpu without refile cache (removing getting refile targets from the code) 18.79% [.] mark_object 8.23% [.] re_match_2_internal 5.88% [.] rpl_re_search_2 4.06% [.] buf_bytepos_to_charpos 3.06% [.] Fmemq 2.45% [.] allocate_vectorlike 1.63% [.] exec_byte_code 1.50% [.] pdumper_marked_p_impl The bottleneck appears to be buf_bytepos_to_charpos, called by BYTE_TO_CHAR macro, which, in turn, is used by set_search_regs buf_bytepos_to_charpos contains the following loop: for (tail = BUF_MARKERS (b); tail; tail = tail->next) { CONSIDER (tail->bytepos, tail->charpos); /* If we are down to a range of 50 chars, don't bother checking any other markers; scan the intervening chars directly now. */ if (best_above - bytepos < distance || bytepos - best_below < distance) break; else distance += BYTECHAR_DISTANCE_INCREMENT; } I am not sure if I understand the code correctly, but that loop is clearly scaling performance with the number of markers Finally, FYI. I plan to work on an alternative mechanism to access Org headings - generic Org query library. It will not use markers and implement ideas from org-ql. org-refile will eventually use that generic library instead of current mechanism. Best, Ihor