[Python-ideas] re.compile_lazy - on first use compiled regexes
bruce at leapyear.org
Sun Mar 24 00:03:19 CET 2013
- compiling regexes is slow so applications frequently compute it once and
- compiling all the regexes at startup slows down startup for regexes that
may never be used
- a common pattern is to compute once at time of use and it would be nice
to optimize this pattern
- the regex library has a cache feature which means that frequently it will
be optimized automatically
- however, there's no guarantee that the regex you care about won't fall
out of the cache.
I think this addresses all the issues better than compute_lazy:
When keep=True is specified, the regex library keeps the cached value for
the lifetime of the process. The regex is computed only once on first use
and you don't need to create a place to store it. Furthermore, if you use
the same regex in more than one place, once with keep=True, the other uses
will automatically be optimized.
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...
More information about the Python-ideas