Subject: Re: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c)

From: Ihor Radchenko <[email-masked]>
Date: Wed, 03 May 2023 15:05:06 +0000

Mattias Engdegård <[email-masked]> writes:

> 3 maj 2023 kl. 11.36 skrev Ihor Radchenko <[email-masked]>:
>
>> Yet, in my tests, I am unable to see any improvement when I consolidate
>> the regexps.
>
> That's odd, but do you get a better cache hit rate (assuming a cache size of 20)?

With the default cache size of 20,
(benchmark-progn
  (setq regexp-cache-hit 0 regexp-cache-miss 0)
  (set-regexp-cache-size 20)
  (org-element-parse-buffer)
  nil)

(cond ((looking-at-p ...) ...)) gives

misses: 1493570
hits: 3225203
% misses from total: 31%

giant rx + looking-at gives

misses: 1177242
hits: 3233553
% misses from total: 27%

>> The version with giant single rx form is actually slower overall (!),
>> making no difference at all in `org-element--current-element'.
>
> Can't say what's going on here, really. Normally a combined regexp
> shouldn't be slower. Are you sure you get the same parse?

All the tests are passing...

Note that I am using `looking-at-p'

I now also tried replacing `looking-at-p' with `looking-at' and I get

        4880  21% + org-element--current-element

        (previous data with `looking-at-p')
        4160  21% + org-element--current-element 

with total time increasing compared to the version with `looking-at-p'
(21.743226s (1.364015s in 2 GCs) compared to 21.035765s (1.091127s in 2 GCs))

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>