From: Danny McClanahan <dmcc2@hypnicjerk.ai>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: Helmut Eller <eller.helmut@gmail.com>,
Eli Zaretskii <eliz@gnu.org>,
pipcet@protonmail.com, emacs-devel@gnu.org, mattiase@acm.org,
acorallo@gnu.org, monnier@iro.umontreal.ca,
stefankangas@gmail.com
Subject: Re: [PATCH] add compiled regexp primitive lisp object
Date: Wed, 07 Aug 2024 15:23:53 +0000 [thread overview]
Message-ID: <pyTIqZ4cxRjDig_DX48kd0p5pXJgV166DadnyVQqlZtfO1QQwrcVhi2ztc6KcvGgbpJmmAMwdYzRFhMCJC4SX5qAKQ53QjmMLoW9zbpkARc=@hypnicjerk.ai> (raw)
In-Reply-To: <87o764sb6y.fsf@gmail.com>
On Wednesday, August 7th, 2024 at 08:43, Helmut Eller <eller.helmut@gmail.com> wrote:
> An advantage of regex objects is that they don't require the regexp
> cache. The regex cache is relatively small (20 entries) and e.g. in the
> scratch buffer, the font lock regexps are recompiled on every
> keystroke because the cache doesn't have enough capacity.
> Interestingly, this seems to have very little performance impact.
>
> Of course, one could make the cache bigger, but for things like font
> lock, pre-compiled regexps seem like a good solution.
I'm currently running the elb-scroll benchmark along with the elp profiler to
identify hot search methods. I think it's possible to introduce a special API
for pre-compiled regexps for these calls, and I'm hoping to have a prototype of
that. Or I was, before I considered the following:
On Wednesday, August 7th, 2024 at 09:40, Augusto Stoffel <arstoffel@gmail.com> wrote:
> > An advantage of regex objects is that they don't require the regexp
> > cache. The regex cache is relatively small (20 entries) and e.g. in the
> > scratch buffer, the font lock regexps are recompiled on every
> > keystroke because the cache doesn't have enough capacity.
> > Interestingly, this seems to have very little performance impact.
> >
> > Of course, one could make the cache bigger, but for things like font
> > lock, pre-compiled regexps seem like a good solution.
>
>
> Ignoring the issue that regexps may be syntax-table dependent and other
> complications (issues which also would need to be addressed in the
> proposed approach), what would be the advantage of exposing compiled
> regexp objects versus having an infinite regexp cache?
>
> If a long-living string (e.g. a string literals appearing in
> Elisp/bytecode files) is used once as a regexp, it will presumably be
> used often as such; so it seems to make sense to keep the cached regexp
> around forever (in the same way that one would keep the regexp object
> around forever).
>
> If a short-lived string is used as a regexp (e.g. an isearch query), one
> could just as well wait and deallocate the cached regexp at the time
> when the string is garbage-collected (in the same way that the compiled
> regexp object would be garbage-collected at some point).
>
> I fail to imagine a case where one would want to let the regexp object
> be garbage-collected but keep the string around.
Ah, it took me quite a long time to understand this, but I'm totally on
board now. I had been coming at this totally backwards, and I did not
at all realize how (as you say) the regexp string is already exactly the key we
need to use for caching. I think I like this much more than trying to introduce
a special caching API for font-lock.
Syntax table notwithstanding, I will absolutely be trying this infinite cache
approach now. This is very clever.
Thanks,
Danny
next prev parent reply other threads:[~2024-08-07 15:23 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 5:08 [PATCH] add compiled regexp primitive lisp object Danny McClanahan
2024-07-30 13:02 ` Philip Kaludercic
2024-07-31 22:33 ` dmcc2
2024-08-01 1:04 ` Pip Cet
2024-08-04 23:38 ` Danny McClanahan
2024-08-05 3:47 ` dmcc2
2024-08-05 4:39 ` Danny McClanahan
2024-08-05 7:15 ` Danny McClanahan
2024-08-05 17:55 ` Pip Cet
2024-08-06 15:15 ` Danny McClanahan
2024-08-06 15:57 ` Eli Zaretskii
2024-08-07 4:28 ` Danny McClanahan
2024-08-06 18:18 ` Pip Cet
2024-08-06 18:38 ` Eli Zaretskii
2024-08-07 4:23 ` Danny McClanahan
2024-08-07 12:00 ` Eli Zaretskii
2024-08-07 12:43 ` Helmut Eller
2024-08-07 13:40 ` Augusto Stoffel
2024-08-07 15:23 ` Danny McClanahan [this message]
2024-08-14 1:32 ` Stefan Monnier
2024-08-07 15:02 ` Danny McClanahan
2024-08-07 15:23 ` Eli Zaretskii
2024-08-14 1:25 ` Stefan Monnier
2024-08-07 7:59 ` Danny McClanahan
2024-08-06 12:08 ` Eli Zaretskii
2024-08-01 8:30 ` Andrea Corallo
2024-08-01 10:06 ` Gerd Möllmann
2024-08-06 13:47 ` Danny McClanahan
2024-08-06 13:57 ` Danny McClanahan
2024-08-07 7:21 ` Andrea Corallo
2024-08-07 8:27 ` Danny McClanahan
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='pyTIqZ4cxRjDig_DX48kd0p5pXJgV166DadnyVQqlZtfO1QQwrcVhi2ztc6KcvGgbpJmmAMwdYzRFhMCJC4SX5qAKQ53QjmMLoW9zbpkARc=@hypnicjerk.ai' \
--to=dmcc2@hypnicjerk.ai \
--cc=acorallo@gnu.org \
--cc=arstoffel@gmail.com \
--cc=eliz@gnu.org \
--cc=eller.helmut@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=mattiase@acm.org \
--cc=monnier@iro.umontreal.ca \
--cc=pipcet@protonmail.com \
--cc=stefankangas@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.