[Python-ideas] re.compile_lazy - on first use compiled regexes

Bruce Leban bruce at leapyear.org
Sun Mar 24 00:34:26 CET 2013

On Sat, Mar 23, 2013 at 4:14 PM, Gregory P. Smith <greg at krypto.org> wrote:

> keep=True defeats the purpose of a caching strategy.  An re.compile call
> within some code somewhere is typically not in a position to know if it is
> going to be called a lot.
> I think the code, as things are now, with dynamic construction at runtime
> based on a simple test is the best of both worlds to avoid the more
> complicated cost of calling re.compile and going through its cache logic.
>  If the caching is ever is improved in the future to be faster, the code
> can arguably be simplified to use re.search or re.match directly and rely
> solely on the caching.
> ie: don't change anything.
Truth is people are currently doing caching themselves, by compiling and
then keeping the compiled regex. Saying they're not in a position to know
whether or not to do that isn't going to change that. Is it worthwhile
having the regex library facilitate this manual caching?

--- Bruce
Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
Learn how hackers think: http://j.mp/gruyere-security
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130323/5630a980/attachment.html>

More information about the Python-ideas mailing list