GNU bug report logs - #63225
Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c)

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Tue, 2 May 2023 07:35:02 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias EngdegÄrd <mattiase <at> acm.org>
Cc: 63225 <at> debbugs.gnu.org, yantar92 <at> posteo.net
Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c)
Date: Tue, 02 May 2023 18:25:18 +0300
> Cc: 63225 <at> debbugs.gnu.org
> From: Mattias EngdegÄrd <mattiase <at> acm.org>
> 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.




This bug report was last modified 2 years and 61 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.