Re:Python to get Google-backed speedup
by amix on Saturday June 13, 2009 @07:27PM
(#656616)
That's actually untrue. If you look in the implementation of the `re` module you would see that it caches the compilation of any regular expression.
[ Parent
| on HN ]
Aha -- I almost suggested that they could do some memoization, and indeed they are doing just that. The last 100 unique patterns are compiled and stored in a dictionary for future use. You could still thrash badly if your regex "working set" is more than 100 patterns, but for most people it's probably Good Enough. (Plus you could override re._MAXCACHE if you really want.)
Thanks for pointing out my error, and getting me to read the actual code instead of speculating. :)