You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider using lru_cache for the re.py caches #72380
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/serhiy-storchaka'closed_at=<Date2016-09-19.03:18:38.645>created_at=<Date2016-09-17.20:06:04.764>labels= ['3.7', 'library', 'performance']
title='Consider using lru_cache for the re.py caches'updated_at=<Date2016-09-19.03:18:38.644>user='https://github.com/rhettinger'
The last time we applied the LRU cache to the re.py module, the overhead of the pure python version resulted in a net performance decrease. But now we have a highly performance C version and should consider reinstating the code.
Yes, I saw that. If a function could raise a NoCache exception, re._compile() could take advantage of it. But I don't feel good about going down that path (adding coupling between the caching decorator and the cached function). It would be better to keep the lru_cache API simple. I already made the mistake of expanding the API for typed=True just to accommodate a single use case (re.compile).
Activity
rhettinger commentedon Sep 17, 2016
The last time we applied the LRU cache to the re.py module, the overhead of the pure python version resulted in a net performance decrease. But now we have a highly performance C version and should consider reinstating the code.
serhiy-storchaka commentedon Sep 17, 2016
Since that time the logic of re._compile() was changed. Now it can't just be wrapped with lru_cache().
serhiy-storchaka commentedon Sep 18, 2016
Added comments on Rietveld.
serhiy-storchaka commentedon Sep 18, 2016
lru_cache can be used for re._compile() if add the ability to bypass the cache and to validate cached value.
rhettinger commentedon Sep 18, 2016
Yes, I saw that. If a function could raise a NoCache exception, re._compile() could take advantage of it. But I don't feel good about going down that path (adding coupling between the caching decorator and the cached function). It would be better to keep the lru_cache API simple. I already made the mistake of expanding the API for typed=True just to accommodate a single use case (re.compile).
serhiy-storchaka commentedon Sep 18, 2016
Yes, raising an exception with a result as a payload is one option. Other option is to check a result. Something like:
rhettinger commentedon Sep 19, 2016
I think I'll just take the low hanging fruit in _compile_repl and call it a day.
python-dev commentedon Sep 19, 2016
New changeset 88110cfbf4dc by Raymond Hettinger in branch '3.6':
Issue bpo-28193: Use lru_cache in the re module.
https://hg.python.org/cpython/rev/88110cfbf4dc