From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Date: Sun, 7 May 2023 14:45:36 +0200 Message-ID: References: <63882A45-BD02-40D5-92FA-70175267BA3B@acm.org> <874jou7lsf.fsf@localhost> <37EED5F9-F1FE-46B6-B4FA-0B268B945123@gmail.com> <87wn1qqvj0.fsf@localhost> <34F4849A-CB39-4C96-9CC1-11ED723706DA@gmail.com> <87wn1psqny.fsf@localhost> <6DAF37F9-B236-4C33-8E30-0FCA47CCBCC5@gmail.com> <87zg6lfobh.fsf@localhost> <281B22C2-CD69-4495-A97C-E754446CA9A6@gmail.com> <87o7n1v1w3.fsf@localhost> <878E8D66-A548-42E6-B077-6068A8B131D8@gmail.com> <87ednvul22.fsf@localhost> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_72D6074B-8E17-43A7-BA13-992D511AF733" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16515"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63225@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 07 14:46:12 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 1pvdmF-0004AB-MS for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 May 2023 14:46:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pvdm7-0001jC-Vc; Sun, 07 May 2023 08:46:04 -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 1pvdm6-0001ij-AW for bug-gnu-emacs@gnu.org; Sun, 07 May 2023 08:46:02 -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 1pvdm5-0007OT-Ra for bug-gnu-emacs@gnu.org; Sun, 07 May 2023 08:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pvdm5-0003nR-La for bug-gnu-emacs@gnu.org; Sun, 07 May 2023 08:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 May 2023 12:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63225 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 63225-submit@debbugs.gnu.org id=B63225.168346354614566 (code B ref 63225); Sun, 07 May 2023 12:46:01 +0000 Original-Received: (at 63225) by debbugs.gnu.org; 7 May 2023 12:45:46 +0000 Original-Received: from localhost ([127.0.0.1]:36648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvdlp-0003ms-Ml for submit@debbugs.gnu.org; Sun, 07 May 2023 08:45:45 -0400 Original-Received: from mail-lf1-f46.google.com ([209.85.167.46]:59773) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pvdlo-0003me-Bs for 63225@debbugs.gnu.org; Sun, 07 May 2023 08:45:44 -0400 Original-Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-4f13ef4ad91so4054985e87.3 for <63225@debbugs.gnu.org>; Sun, 07 May 2023 05:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683463538; x=1686055538; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=mkqs5c0ZSio6ks4fBti2i3SVquYlICDdSmJzKoJ2CYU=; b=OvX9Hxlv4irjkRlExmyImr6O8kBhFpZbnCY1KWIPZz5DuZ6ZGKDeZrSm7Ynje47RuQ ANHe4pMpGzYuoTl3nkz0hJ8dWOY/9csOH8/H6Vf0ehh9AklSexmstEshgUULkjRNZINZ 39m9ea7TxDZFGKfe6nw8M8O9EUggm328UqSQXec9qogiPnDoLSgVwhwcfHYalIviLIf+ HNySFQH1TV6B2b7orOWbPa9f5beo+IiG3SIC3xppS/lzJ1dAKhqfv3G6jXk/FdyM1Sv9 XLZrl5PUMUQASJihfON3xgTRysdonZGmz+1PtAdW8SrTc5TT3XXL7qUUt9+pK4CZI73i RFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683463538; x=1686055538; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mkqs5c0ZSio6ks4fBti2i3SVquYlICDdSmJzKoJ2CYU=; b=A7P7UnzdKaZ1MAwF7NP0TX+8B4lJHwIxDXzTeJh0JpB8oyzAmPxeWh4Su6e6fb7sRY wESfhaW7Zo+fDpxTLD0OY8J3BcMM9j7apLPQaAAFOLYnLJJSbBdT5eI6iT7YPzKhKKsG xe2mqNgmaYy/g16vZ6/c7607NSsWiBIZ8E3QQ851Kg4eO6VQEXKhaeuGhUdyWzC2r03h 88JE0kglrIq45ZuiaFQ8lhifxQ2PtfwhMMdoiqjVMK9iszLFGm3a6PRypcse/kmWrOHH ANqhpoyukByFl+KNrto4In91RPYn8csQkhIFF9qL9pN+Nctpr2r1iSTPxfWhTUjRdaYh 9pUA== X-Gm-Message-State: AC+VfDyLrSON4j26/fn9OYS/Sh1iR8K0G/1ci96oI/XT2ANnQONQIZP5 rVPIprQnrd793OH94dZT9ws= X-Google-Smtp-Source: ACHHUZ6QBqwx8q5Q87p+HCY3JJYISDT+2VknSxpX3s4c86m6uSV1t+HlZkiztGhk++AxQtj34XdNZA== X-Received: by 2002:ac2:5293:0:b0:4f1:408f:4fa6 with SMTP id q19-20020ac25293000000b004f1408f4fa6mr2115324lfm.49.1683463538015; Sun, 07 May 2023 05:45:38 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id v16-20020a056512049000b004ddaea30ba6sm961922lfq.235.2023.05.07.05.45.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 May 2023 05:45:36 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.15) 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:261255 Archived-At: --Apple-Mail=_72D6074B-8E17-43A7-BA13-992D511AF733 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 5 maj 2023 kl. 18.26 skrev Mattias Engdeg=C3=A5rd = : > Stupid printf-debugging actually, nothing fancier than that. Here is some of that stupidity I promised. You probably want to use it = with (set-regexp-trace-file "re.log") (unwind-protect (do-something-interesting) (set-regexp-trace-file nil)) so that you don't trace more than necessary. The file may become large, = but it's useful data for off-line analysis, scripted or just looking at = it in an editor. The first letter of each line indicates a regexp cache hit (H) or miss = (M). --Apple-Mail=_72D6074B-8E17-43A7-BA13-992D511AF733 Content-Disposition: attachment; filename=0003-Regexp-tracing-add-set-regexp-trace-file.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0003-Regexp-tracing-add-set-regexp-trace-file.patch" Content-Transfer-Encoding: quoted-printable =46rom=20cd66a560a74d2ed94202cab278455544f0c9337c=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Sun,=207=20May=202023=2014:05:31=20+0200=0A= Subject:=20[PATCH=203/3]=20Regexp=20tracing:=20add=20= set-regexp-trace-file=0A=0A---=0A=20src/search.c=20|=2048=20= ++++++++++++++++++++++++++++++++++++++++++++++++=0A=201=20file=20= changed,=2048=20insertions(+)=0A=0Adiff=20--git=20a/src/search.c=20= b/src/search.c=0Aindex=20c454d5e1ca9..b378db152a2=20100644=0A---=20= a/src/search.c=0A+++=20b/src/search.c=0A@@=20-34,6=20+34,10=20@@=20= Copyright=20(C)=201985-1987,=201993-1994,=201997-1999,=202001-2023=20= Free=20Software=0A=20=0A=20#include=20"regex-emacs.h"=0A=20=0A+#include=20= =0A+=0A+static=20FILE=20*regexp_trace_file=20=3D=20NULL;=0A+=0A=20= #define=20DEFAULT_REGEXP_CACHE_SIZE=2020=0A=20=0A=20/*=20If=20the=20= regexp=20is=20non-nil,=20then=20the=20buffer=20contains=20the=20compiled=20= form=0A@@=20-200,6=20+204,7=20@@=20compile_pattern=20(Lisp_Object=20= pattern,=20struct=20re_registers=20*regp,=0A=20{=0A=20=20=20struct=20= regexp_cache=20*cp,=20**cpp,=20**lru_nonbusy;=0A=20=0A+=20=20bool=20= cache_hit=20=3D=20false;=0A=20=20=20for=20(cpp=20=3D=20&searchbuf_head,=20= lru_nonbusy=20=3D=20NULL;=20;=20cpp=20=3D=20&cp->next)=0A=20=20=20=20=20= {=0A=20=20=20=20=20=20=20cp=20=3D=20*cpp;=0A@@=20-224,6=20+229,7=20@@=20= compile_pattern=20(Lisp_Object=20pattern,=20struct=20re_registers=20= *regp,=0A=20=09=20=20&&=20cp->buf.charset_unibyte=20=3D=3D=20= charset_unibyte)=0A=20=20=20=20=20=20=20=20=20{=0A=20=20=20=20=20=20=20=20= =20=20=20regexp_cache_hit++;=0A+=09=20=20cache_hit=20=3D=20true;=0A=20=20= =20=20=20=20=20=20=20=20=20break;=0A=20=20=20=20=20=20=20=20=20}=0A=20=0A= @@=20-243,6=20+249,26=20@@=20compile_pattern=20(Lisp_Object=20pattern,=20= struct=20re_registers=20*regp,=0A=20=09}=0A=20=20=20=20=20}=0A=20=0A+=20=20= if=20(regexp_trace_file)=20{=0A+=20=20=20=20fprintf(regexp_trace_file,=20= "%c=20\"",=20cache_hit=20?=20'H'=20:=20'M');=0A+=20=20=20=20ptrdiff_t=20= n=20=3D=20SBYTES=20(pattern);=0A+=20=20=20=20for=20(ptrdiff_t=20i=20=3D=20= 0;=20i=20<=20n;=20i++)=20{=0A+=20=20=20=20=20=20unsigned=20char=20c=20=3D=20= SREF=20(pattern,=20i);=0A+=20=20=20=20=20=20switch=20(c)=20{=0A+=20=20=20= =20=20=20case=20'"':=20case=20'\\':=20fprintf(regexp_trace_file,=20= "\\%c",=20c);=20break;=0A+=20=20=20=20=20=20case=20'\n':=20= fprintf(regexp_trace_file,=20"\\n");=20break;=0A+=20=20=20=20=20=20case=20= '\t':=20fprintf(regexp_trace_file,=20"\\t");=20break;=0A+=20=20=20=20=20=20= default:=0A+=09if=20(c=20<=2032=20||=20c=20=3D=3D=20127)=0A+=09=20=20= fprintf(regexp_trace_file,=20"\\x%02x",=20c);=0A+=09else=0A+=09=20=20= putc(c,=20regexp_trace_file);=0A+=09break;=0A+=20=20=20=20=20=20}=0A+=20=20= =20=20}=0A+=20=20=20=20fprintf(regexp_trace_file,=20"\"\n");=0A+=20=20}=0A= +=0A=20=20=20/*=20When=20we=20get=20here,=20cp=20(aka=20*cpp)=20contains=20= the=20compiled=20pattern,=0A=20=20=20=20=20=20either=20because=20we=20= found=20it=20in=20the=20cache=20or=20because=20we=20just=20compiled=20= it.=0A=20=20=20=20=20=20Move=20it=20to=20the=20front=20of=20the=20queue=20= to=20mark=20it=20as=20most=20recently=20used.=20=20*/=0A@@=20-3424,6=20= +3450,27=20@@=20DEFUN=20("set-regexp-cache-size",=20= Fset_regexp_cache_size,=20Sset_regexp_cache_size,=0A=20=20=20return=20= Qnil;=0A=20}=0A=20=0A+DEFUN=20("set-regexp-trace-file",=20= Fset_regexp_trace_file,=20Sset_regexp_trace_file,=0A+=20=20=20=20=20=20=20= 1,=201,=200,=0A+=20=20=20=20=20=20=20doc:=20/*=20Set=20the=20regexp=20= trace=20file=20to=20FILE.=20=20Internal=20use=20only.=0A+Use=20`nil'=20= as=20argument=20to=20stop=20tracing.=20=20*/)=0A+=20=20(Lisp_Object=20= file)=0A+{=0A+=20=20if=20(NILP=20(file))=20{=0A+=20=20=20=20fclose=20= (regexp_trace_file);=0A+=20=20=20=20regexp_trace_file=20=3D=20NULL;=0A+=20= =20}=20else=20{=0A+=20=20=20=20CHECK_STRING=20(file);=0A+=20=20=20=20if=20= (regexp_trace_file)=0A+=20=20=20=20=20=20Fset_regexp_trace_file=20= (Qnil);=0A+=20=20=20=20FILE=20*f=20=3D=20fopen=20(SSDATA=20(file),=20= "a");=0A+=20=20=20=20if=20(!f)=0A+=20=20=20=20=20=20report_file_error=20= ("opening=20regexp=20trace=20file",=20file);=0A+=20=20=20=20= regexp_trace_file=20=3D=20f;=0A+=20=20}=0A+=20=20return=20Qnil;=0A+}=0A+=0A= =20void=0A=20mark_regexp_cache=20(void)=0A=20{=0A@@=20-3514,6=20+3561,7=20= @@=20syms_of_search=20(void)=0A=20=20=20defsubr=20= (&Snewline_cache_check);=0A=20=20=20defsubr=20(&Sregexp_cache_size);=0A=20= =20=20defsubr=20(&Sset_regexp_cache_size);=0A+=20=20defsubr=20= (&Sset_regexp_trace_file);=0A=20=0A=20=20=20= pdumper_do_now_and_after_load=20(syms_of_search_for_pdumper);=0A=20}=0A= --=20=0A2.32.0=20(Apple=20Git-132)=0A=0A= --Apple-Mail=_72D6074B-8E17-43A7-BA13-992D511AF733--