[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rx.el sexp regexp syntax

From: Tom Tromey
Subject: Re: rx.el sexp regexp syntax
Date: Sun, 27 May 2018 10:56:36 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

>>>>> "Alan" == Alan Mackenzie <address@hidden> writes:

>> Building the automaton is costly.  In C, we build it once and save the
>> result in a variable so that every regexp match does not rebuild the
>> automaton each time.

Alan> Emacs has a (moderately large) cache of regexps, so that building the
Alan> automatons is done very rarely.  Possibly just once each for each
Alan> session of Emacs.

I wonder about both of these statements.

On the one hand, AFAICT the regex cache is 20 items.  From search.c:

   #define REGEXP_CACHE_SIZE 20

That seems pretty small to me, given how prevalent regexps are in elisp.

On the other hand, in the past when I have tried to profile Emacs, I
haven't seen regexp compilation show up too much.  IIRC I did see regexp
matching and the GC.  Maybe this just points out the efficacy of the
cache -- maybe 20 items is plenty.

Perhaps the regexp matcher could use some micro-optimizations, like the
token-threading the bytecode interpreter does.

Alan> Are you suggesting here building an interpreter in Lisp directly to
Alan> execute rx expressions?

It's interesting, IMO, to consider compiling rx (or regexps generally)
to lisp bytecode.  Perhaps with the JIT, it would boost performance in
some cases.  (It may be slower, but it's worthwhile to do the

For other work in this area see Stefan's lex-parse-re package.  I think
it includes a regexp matcher in elisp.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]