From: Ihor Radchenko <yantar92@posteo.net>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: 63225@debbugs.gnu.org
Subject: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c)
Date: Tue, 09 May 2023 12:02:19 +0000 [thread overview]
Message-ID: <871qjp1zn8.fsf@localhost> (raw)
In-Reply-To: <67AAB661-8B27-4D09-BF0D-6B76ABB54477@gmail.com>
Mattias Engdegård <mattias.engdegard@gmail.com> writes:
> 8 maj 2023 kl. 21.38 skrev Ihor Radchenko <yantar92@posteo.net>:
>
>> Does this imply that simple regexps like
>>
>> (looking-at-p (rx (seq bol (zero-or-more (any "\t ")) "#" (or " " eol))))
>>
>> should better be implemented as the following?
>
> Obviously this isn't practical or beneficial for any but the simplest patterns. Benchmark if you are concerned.
> It is useful to know when (not) to use regexps.
I did some benchmarking and your code does provide >2x improvement. Most
of it is coming from using `forward-line' instead of
`beginning-of-line'.
I benchmarked different variations:
(defun yant/test1 ()
(save-excursion
(forward-line 0) ; faster than beginning-of-line
(skip-chars-forward "[:blank:]") ; faster than looking-at-p
(not (eolp)))) ; very cheap
(defun yant/test2 ()
(save-excursion
(beginning-of-line 0)
(not (looking-at-p "[[:blank:]]*$"))))
(defun yant/test3 ()
(save-excursion
(beginning-of-line 0)
(skip-chars-forward "[:blank:]") ; faster than looking-at-p
(not (eolp))))
(defun yant/test4 ()
(save-excursion
(forward-line 0) ; faster than beginning-of-line
(not (looking-at-p "[[:blank:]]*$"))))
- forward-line + skip-chars-forward :: (2.980 2 0.648)
- beginning-of-line + looking-at-p :: (7.189 2 0.653)
- beginning-of-line + skip-chars-forward :: (6.833 2 0.634)
- forward-line + looking-at-p :: (3.180 2 0.663)
>> I really hope that I did not need to do all these workarounds specific to
>> current implementation pitfalls of Emacs regexp compiler.
>
> Some of them. We program for the system we have. Emacs is a very slowly moving target.
Will it make sense to use a combination of char-after and
skip-chars-forward every single time?
I am thinking about something among the lines of
(defconst org-fancy-re
(propertize
(rx bol (1+ "*") " ")
'org-re-direct
'(progn
(and
(bolp)
(> (skip-chars-forward "*") 0)
(prog1 (eq ?\s (char-after)) (forward-char))))))
(define-inline org-fancy-looking-at-p (regexp)
"Like `looking-at-p', but try `org-re-direct' property."
(let ((sexp (and (inline-const-p regexp)
(get-text-property
'org-re-direct
(inline-const-val regexp)))))
(if sexp (inline-quote (save-excursion ,sexp))
(inline-quote (looking-at-p ,regexp)))))
>>> I would like that too, but changing that isn't easy.
>>
>> I am sure that it is easy.
>
> I didn't mean technically. Code is easy to write.
May you elaborate what is the blocker then?
--
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>
next prev parent reply other threads:[~2023-05-09 12:02 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-02 7:37 bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Ihor Radchenko
2023-05-02 14:33 ` Mattias Engdegård
2023-05-02 15:25 ` Eli Zaretskii
2023-05-02 15:28 ` Mattias Engdegård
2023-05-02 17:30 ` Eli Zaretskii
2023-05-02 17:58 ` Ihor Radchenko
2023-05-02 16:14 ` Ihor Radchenko
2023-05-02 21:00 ` Mattias Engdegård
2023-05-02 21:21 ` Ihor Radchenko
2023-05-03 8:39 ` Mattias Engdegård
2023-05-03 9:36 ` Ihor Radchenko
2023-05-03 13:59 ` Mattias Engdegård
2023-05-03 15:05 ` Ihor Radchenko
2023-05-03 15:20 ` Mattias Engdegård
2023-05-03 16:02 ` Ihor Radchenko
2023-05-04 9:24 ` Mattias Engdegård
2023-05-05 10:31 ` Ihor Radchenko
2023-05-05 16:26 ` Mattias Engdegård
2023-05-06 13:38 ` Ihor Radchenko
2023-05-07 10:32 ` Mattias Engdegård
2023-05-08 11:58 ` Ihor Radchenko
2023-05-08 18:21 ` Mattias Engdegård
2023-05-08 19:38 ` Ihor Radchenko
2023-05-08 19:53 ` Mattias Engdegård
2023-05-09 8:36 ` bug#63225: Using char table-based finite-state machines as a replacement for re-search-forward (was: bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c)) Ihor Radchenko
2023-05-09 12:02 ` Ihor Radchenko [this message]
2023-05-09 15:05 ` bug#63225: Compiling regexp patterns (and REGEXP_CACHE_SIZE in search.c) Mattias Engdegård
2023-05-09 15:56 ` Ihor Radchenko
2023-05-09 15:57 ` Mattias Engdegård
2023-05-07 12:45 ` Mattias Engdegård
2023-05-08 13:56 ` Ihor Radchenko
2023-05-08 19:32 ` Mattias Engdegård
2023-05-08 19:44 ` Ihor Radchenko
2023-05-04 12:58 ` Ihor Radchenko
2023-05-02 23:36 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871qjp1zn8.fsf@localhost \
--to=yantar92@posteo.net \
--cc=63225@debbugs.gnu.org \
--cc=mattias.engdegard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).