From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Date: Tue, 02 May 2023 18:25:18 +0300 Message-ID: <83sfcen4bl.fsf@gnu.org> References: <87ttwvgp4s.fsf@localhost> <63882A45-BD02-40D5-92FA-70175267BA3B@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30950"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63225@debbugs.gnu.org, yantar92@posteo.net To: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 02 17:25:24 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 1ptrsZ-0007qA-LK for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 02 May 2023 17:25:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptrsF-0003LY-6K; Tue, 02 May 2023 11:25:03 -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 1ptrsE-0003LJ-Jt for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:25: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 1ptrsE-0007In-Az for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ptrsD-0007gy-Oc for bug-gnu-emacs@gnu.org; Tue, 02 May 2023 11:25:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 May 2023 15:25: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.168304108729541 (code B ref 63225); Tue, 02 May 2023 15:25:01 +0000 Original-Received: (at 63225) by debbugs.gnu.org; 2 May 2023 15:24:47 +0000 Original-Received: from localhost ([127.0.0.1]:44842 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptrrz-0007gO-2J for submit@debbugs.gnu.org; Tue, 02 May 2023 11:24:47 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:52754) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ptrru-0007g4-SI for 63225@debbugs.gnu.org; Tue, 02 May 2023 11:24:45 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptrrp-0007GV-5l; Tue, 02 May 2023 11:24:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=GzyTW1zd79cWFyUI7R8nYeQZMFKbuDeJuEDHzW9n2tU=; b=QhZGUotufJ2DMmhAfmTd GhEw3ltd5hJ45jRHmiwA2B/XlhBh/7CFIo0UWUr2AfRiEvRC2+GiIy0hghqtbKrTP5PE1F1nwz/1e eioOI0S5rAofx2yMh88U1HLK9UrjF8GRynGu1D3p69lGwObLcosc/Pdh6R9vVuSaU3ZK0xF7PX1Hz ML3/HEXMXehuYHaVLOnnuuEH6uHw5R2j7InVqnbVyTKSl+kft58AsoN/2Mc9Ne+YX/qMZJW1FZh5N Qf2np4c0RPgBtG2hhQtogoesbJCcSmgciiuPDhSGtzF4bgx4qJ4cz+QTZTUTLKLLESM24LQLwtqwu 2uPuTVIUdH6UqA==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptrrn-0002Dv-GT; Tue, 02 May 2023 11:24:35 -0400 In-Reply-To: <63882A45-BD02-40D5-92FA-70175267BA3B@acm.org> (message from Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= on Tue, 2 May 2023 16:33:58 +0200) 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:260940 Archived-At: > Cc: 63225@debbugs.gnu.org > From: Mattias EngdegÄrd > Date: Tue, 2 May 2023 16:33:58 +0200 > > Indeed it sounds like you are suffering from regexp cache thrashing. I'm attaching two patches: one to measure the cache miss rate, and one that allows the regexp cache size to be changed at run time. Thanks, but the new primitives need to be documented (why do the doc strings say "internal use only"?), and also we should include the cache size in the output of memory-report. > +static void > +set_regexp_cache_size (int n) > +{ > + for (int i = 0; i < regexp_cache_size; i++) > + xfree (searchbufs[i].buf.buffer); > + > + size_t bytes = n * sizeof *searchbufs; > + searchbufs = xrealloc (searchbufs, bytes); > + memset (searchbufs, 0, bytes); > + regexp_cache_size = n; > + Should this first check that the new size is identical to the old one, and if so, do nothing? Come to think of this, do we really need to realloc if the new size is smaller? And why zero out the cache when changing the size? > +DEFUN ("regexp-cache-size", Fregexp_cache_size, Sregexp_cache_size, > + 0, 0, 0, > + doc: /* Current regexp cache size. Internal use only. */) > + (void) > +{ > + return make_int (regexp_cache_size); > +} Since the size of the cache is a fixnum, why not use make_fixnum here? it's a tad faster.