From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Date: Tue, 02 May 2023 07:37:39 +0000 Message-ID: <87ttwvgp4s.fsf@localhost> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6437"; mail-complaints-to="usenet@ciao.gmane.io" To: 63225@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 02 09:35:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ptkXf-0001Vc-E3 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 May 2023 09:35:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptkXU-0008MV-Mt; Tue, 02 May 2023 03:35:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptkXS-0008M6-M6 for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 03:35:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ptkXO-0007N5-MM for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 03:35:06 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ptkXO-0007Dj-HS for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 03:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 May 2023 07:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63225 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168301290127742 (code B ref -1); Tue, 02 May 2023 07:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 May 2023 07:35:01 +0000 Original-Received: from localhost ([127.0.0.1]:41607 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptkXM-0007DN-IU for submit@debbugs.gnu.org; Tue, 02 May 2023 03:35:00 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:48852) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptkXH-0007D8-H3 for submit@debbugs.gnu.org; Tue, 02 May 2023 03:34:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptkXD-0008LW-Bc for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 03:34:55 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptkX9-0007LP-So for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 03:34:51 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 7052924028C for ; Tue, 2 May 2023 09:34:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1683012884; bh=9hmokUBykZPsYxKdGVwwxSzsjcB+aFFtzdCG3O/htZ0=; h=From:To:Subject:Date:From; b=KWn6QP8rfHmS9VGMM9w41lO7x5fClZj382NEnVwOxZKkpEN3Iz+AD9CmobZHxFngW qLyIOXCFg31scFoMwWtJVRppd5IdZ9CgJHIGfjAepgoZVVSpYR6iUOYWP/3kRSSrLM tl5/SoNFf0k/vjVo7YKZgqVxl8JAGapwaszn5/fgONh17eFapwFGremUPDUvYqeC3Z qJty/T+ofsLH3vh/uAriyO01jj0okHuesYTK5LBrDGRg5QTzUipR49Lz9Nphf8WYuB pZpZKIBRIW+oUhyBMjareJu61V4EnDUAMPf3nfWY52jikFuVFfcR/r9oUr2AeEIpX5 KSFhQ42pqnSLQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Q9X0G4Rv4z6tyM for ; Tue, 2 May 2023 09:34:38 +0200 (CEST) Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260904 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Hello, I am now studying the performance of Org mode parser on huge Org files. I noticed that `org-element-parse-buffer' spends a significant (~10%) fraction of CPU time simply compiling regexp patterns. This happens because Org parser performs a huge number repeated regexp searches as it incrementally parses the buffer. The searches happen on a fixed set of regexp patterns (several dozens). I was able to get rid of the regex compilation-related slowdown simply by increasing REGEXP_CACHE_SIZE 10x (see the attached patch). Does anyone know if there are potential side effects of this increase if applied across Emacs? Or, alternatively, may Emacs provide an ability to store compiled regexp patterns from Elisp (similar to what `treesit-query-compile' does)? I suspect that storing pre-compiled patterns may benefit a number of major modes that have to perform complex regexp matching. Best, Ihor In GNU Emacs 30.0.50 (build 4, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo version 1.17.8) of 2023-05-02 built on localhost Repository revision: a0a71ca12d585bca5173775f08eabae553e15659 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101008 System Description: Gentoo Linux Configured using: 'configure --with-native-compilation' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-src-search.c-REGEXP_CACHE_SIZE-Increase-to-200.patch >From f0d9c814ff0601fa3487ad3da1ae4dcdf511d850 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Tue, 2 May 2023 09:28:21 +0200 Subject: [PATCH] * src/search.c (REGEXP_CACHE_SIZE): Increase to 200 --- src/search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index 0bb52c03eef..cfcce3c7293 100644 --- a/src/search.c +++ b/src/search.c @@ -34,7 +34,7 @@ Copyright (C) 1985-1987, 1993-1994, 1997-1999, 2001-2023 Free Software #include "regex-emacs.h" -#define REGEXP_CACHE_SIZE 20 +#define REGEXP_CACHE_SIZE 200 /* If the regexp is non-nil, then the buffer contains the compiled form of that regexp, suitable for searching. */ -- 2.40.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--